Created
August 5, 2018 00:19
-
-
Save juanpasolano/75721b66c4aaeb2bc03105f8f9ccdbea to your computer and use it in GitHub Desktop.
Refetch info graphql
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
import React, { Component } from "react"; | |
import { Query } from "react-apollo"; | |
import { GET_ALL_RECIPES } from "queries"; | |
import RecipeItem from "components/Recipe/RecipeItem"; | |
class AppContent extends Component { | |
componentDidMount() { | |
const { refetch } = this.props; | |
if (refetch) refetch(); | |
} | |
render() { | |
const { data, loading } = this.props; | |
return ( | |
<div className="container"> | |
<h1>Home</h1> | |
<ul> | |
{data && | |
data.getAllRecipes && | |
data.getAllRecipes.map(recipe => { | |
return <RecipeItem key={recipe._id} recipe={recipe} />; | |
})} | |
</ul> | |
</div> | |
); | |
} | |
} | |
const App = () => { | |
return ( | |
<Query query={GET_ALL_RECIPES}>{props => <AppContent {...props} />}</Query> | |
); | |
}; | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment