Last active
July 7, 2018 20:33
-
-
Save jonathanharrell/7125163c12853e08d1bfc89d0c139425 to your computer and use it in GitHub Desktop.
Using FetchData React Component with Render Props
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
class App extends React.Component { | |
constructor(props) { | |
super(props) | |
} | |
render() { | |
return ( | |
<div className="wrapper"> | |
<FetchData | |
url="https://jsonplaceholder.typicode.com/todos" | |
render={({loading, results, error}) => ( | |
<div> | |
{loading && ( | |
<p>Loading...</p> | |
)} | |
{results.length > 0 && ( | |
<div className="results"> | |
{results.map(result => ( | |
<p key={result.id}>{result.title}</p> | |
))} | |
</div> | |
)} | |
{error && ( | |
<p>There was a problem loading.</p> | |
)} | |
</div> | |
)} | |
/> | |
</div> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment