Created
July 19, 2019 18:18
-
-
Save trevorblades/79467e249aab98164fdf8a286c5cf77e to your computer and use it in GitHub Desktop.
Apollo render props vs. hooks (basic example)
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
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> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
apollo hooks