Skip to content

Instantly share code, notes, and snippets.

@trevorblades
Created July 19, 2019 18:18
Show Gist options
  • Save trevorblades/79467e249aab98164fdf8a286c5cf77e to your computer and use it in GitHub Desktop.
Save trevorblades/79467e249aab98164fdf8a286c5cf77e to your computer and use it in GitHub Desktop.
Apollo render props vs. hooks (basic example)
function ProductsList() {
const {loading, error, data} = useQuery(LIST_PRODUCTS);
if (loading) return 'Loading...';
if (error) return error.message;
return (
<ul>
{data.products.map(product => (
<li key={product.id}>{product.name}</li>
))}
</ul>
);
}
function ProductsList() {
return (
<Query query={LIST_PRODUCTS}>
{({loading, error, data}) => {
if (loading) return 'Loading...';
if (error) return error.message;
return (
<ul>
{data.products.map(product => (
<li key={product.id}>{product.name}</li>
))}
</ul>
);
}}
</Query>
);
}
@Jiert
Copy link

Jiert commented Jul 19, 2019

apollo hooks
jake

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment