Skip to content

Instantly share code, notes, and snippets.

@walidvb
Created March 11, 2020 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walidvb/9fb7828fce82d6e52f2d9a0ea71a159a to your computer and use it in GitHub Desktop.
Save walidvb/9fb7828fce82d6e52f2d9a0ea71a159a to your computer and use it in GitHub Desktop.
zippax help
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} />)}
</>
}
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