Created
March 11, 2020 14:52
-
-
Save walidvb/9fb7828fce82d6e52f2d9a0ea71a159a to your computer and use it in GitHub Desktop.
zippax help
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
import { useState, useEffect }, React from 'react' | |
const categoriesURL = (id) => `your-url/categories` | |
export default Category () => { | |
const [categories, setCategories] = useState([]) | |
useEffect(() => { | |
fetch(categoriesURL).then(res => res.json()).then(data => setCategories(data)) | |
}, []) | |
return <> | |
{categories.map(cat => <CategoryItems category={cat} />)} | |
</> | |
} |
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
import { useState, useEffect }, React from 'react' | |
const categoriesItemsURL = (id) => `your-url/items?category_id=${id}` | |
export default CategoryItems ({category}) => { | |
const [items, setItems] = useState([]) | |
useEffect(() => { | |
fetch(categoriesItemsURL(category.id)).then(res => res.json()).then(data => setCategories(data)) | |
}, []) | |
return <> | |
{items.map(item => <Text>{item.name}</Text>)} | |
</> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment