Skip to content

Instantly share code, notes, and snippets.

@juanpasolano
Created August 5, 2018 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanpasolano/75721b66c4aaeb2bc03105f8f9ccdbea to your computer and use it in GitHub Desktop.
Save juanpasolano/75721b66c4aaeb2bc03105f8f9ccdbea to your computer and use it in GitHub Desktop.
Refetch info graphql
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