Skip to content

Instantly share code, notes, and snippets.

@daveols
Last active July 6, 2018 03:02
Show Gist options
  • Save daveols/b3a79ef4c5f6bfd693d48dadb7cf7e02 to your computer and use it in GitHub Desktop.
Save daveols/b3a79ef4c5f6bfd693d48dadb7cf7e02 to your computer and use it in GitHub Desktop.
React Loads - basic bacon example
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