Skip to content

Instantly share code, notes, and snippets.

@keshidong
Created October 7, 2019 11:46
Show Gist options
  • Select an option

  • Save keshidong/54525c02a50adc8292020bfbe08f8b5c to your computer and use it in GitHub Desktop.

Select an option

Save keshidong/54525c02a50adc8292020bfbe08f8b5c to your computer and use it in GitHub Desktop.
const fetchProduct = async (productId) => {
const response = await fetch('http://myapi/product' + productId); // Uses productId prop
const json = await response.json()
return json
}
function ProductPage({ productId }) {
const [product, setProduct] = useState(null)
useEffect(() => {
fetchProduct(productId)
.then((json) => {
setProduct(json)
})
}, [productId])
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment