Skip to content

Instantly share code, notes, and snippets.

@dsdenes
Last active December 23, 2019 13:48
Show Gist options
  • Save dsdenes/ccae9e787e9508637c6ba7e9f3988508 to your computer and use it in GitHub Desktop.
Save dsdenes/ccae9e787e9508637c6ba7e9f3988508 to your computer and use it in GitHub Desktop.
interface GistsProps {
useGists: (page?: number) => [Gist[] | null, string?];
}
export const Gists: React.FC<GistsProps> = props => {
const [page, setPage] = useState(0);
const [gists, error] = props.useGists(page);
if (error !== undefined) {
return <div>{error}</div>;
}
if (gists === null) {
return <div>Loading gists page {page}</div>;
}
return (
<>
<ul>
{gists.map(gist => (
<li>{gist.url}</li>
))}
</ul>
{page > 0 && <button onClick={() => setPage(page - 1)}>Prev</button>}
<button onClick={() => setPage(page + 1)}>Next</button>
</>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment