Created
June 16, 2024 14:31
-
-
Save PaulieScanlon/23946df6fa7b629a1d1ca5e86bb26b5f to your computer and use it in GitHub Desktop.
Vote Page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// app/page.tsx | |
'use client'; | |
import { useState } from 'react'; | |
import config from '../utils/poll-config'; | |
import submitVote from './submit-vote'; | |
export default function Page({ searchParams }) { | |
const { error } = searchParams; | |
const [isSubmitting, setIsSubmitting] = useState(false); | |
const handleClick = (id: string) => { | |
submitVote(id); | |
setIsSubmitting(true); | |
}; | |
return ( | |
<> | |
<h1>Vote</h1> | |
<ul> | |
{config.map((item, index) => { | |
const { name, id } = item; | |
return ( | |
<li key={index}> | |
<button onClick={() => handleClick(id)} disabled={isSubmitting}> | |
<span>{name}</span> | |
</button> | |
</li> | |
); | |
})} | |
{error ? <p>Server error</p> : null} | |
</ul> | |
</> | |
); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment