Last active
July 6, 2018 03:02
-
-
Save daveols/b3a79ef4c5f6bfd693d48dadb7cf7e02 to your computer and use it in GitHub Desktop.
React Loads - basic bacon example
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
const getBacon = () => | |
axios.get('https://baconipsum.com/api/?type=meat-and-filler') | |
const Bacon = () => ( | |
<Loads fn={getBacon}> | |
{({ isIdle, isLoading, isSuccess, response, load }) => ( | |
<div> | |
<button onClick={load}> | |
{isIdle ? 'Get some bacon' : 'Get more bacon'} | |
</button> | |
{isLoading && <p>Coming right up...</p>} | |
{isSuccess && <p>{response[0]}</p>} | |
</div> | |
)} | |
</Loads> | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment