Last active
November 4, 2017 13:01
-
-
Save busypeoples/735c358fc45512d44986f9580b7e5421 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 fakeFetch = () => | |
new Promise((res, rej) => { | |
setTimeout( | |
() => | |
res([ | |
{ id: 1, name: 'foo' }, | |
{ id: 2, name: 'bar' }, | |
{ id: 3, name: 'baz' } | |
]), | |
1000 | |
); | |
}); | |
const App = () => ( | |
<Loader | |
fetch={fakeFetch} | |
renderError={error => ( | |
<div class="error">Something went wrong: {error.message}</div> | |
)} | |
renderSuccess={data => <UserItems data={data} />} | |
renderNotAsked={() => <div className="start">Not Data Loaded</div>} | |
renderLoading={() => <div className="loader">Loading...</div>} | |
> | |
{(View, loadData) => ( | |
<div> | |
{View} | |
<button onClick={loadData}>Load Data</button> | |
</div> | |
)} | |
</Loader> | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment