Last active
December 23, 2019 13:48
-
-
Save dsdenes/ccae9e787e9508637c6ba7e9f3988508 to your computer and use it in GitHub Desktop.
This file contains 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
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