Created
October 7, 2019 11:46
-
-
Save keshidong/54525c02a50adc8292020bfbe08f8b5c to your computer and use it in GitHub Desktop.
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
| 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