Skip to content

Instantly share code, notes, and snippets.

@PaulieScanlon
Created June 16, 2024 14:31
Show Gist options
  • Save PaulieScanlon/23946df6fa7b629a1d1ca5e86bb26b5f to your computer and use it in GitHub Desktop.
Save PaulieScanlon/23946df6fa7b629a1d1ca5e86bb26b5f to your computer and use it in GitHub Desktop.
Vote Page
// 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