Last active
December 23, 2019 14:19
-
-
Save dsdenes/364f5b3b73bcd2a1f21c589829ae508c to your computer and use it in GitHub Desktop.
Fetching in React components, the correct way
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
import { GistList } from './gists.component' | |
import { useGists } from './gists.control' | |
function App () { | |
const [whichList, setWhichList] = useState(0) | |
return ( | |
<> | |
<h1>Fetching GitHub Gists</h1> | |
<button onClick={() => setWhichList(0)}>List 1</button> | |
<button onClick={() => setWhichList(1)}>List 2</button> | |
<h2>Showing list {whichList + 1}</h2> | |
{whichList === 0 && <GistList useGists={useGists} />} | |
{whichList === 1 && <GistList useGists={useGists} />} | |
</> | |
) | |
} | |
// Using CRA boilerplate | |
const rootElement = document.getElementById('root') | |
ReactDOM.render(<App />, rootElement) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment