Created
July 15, 2022 10:34
-
-
Save hesan-aminiloo/55007d03cff880dc421f8a5129e77711 to your computer and use it in GitHub Desktop.
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
const useBrands = () => { | |
const [brands, setBrands] = useState([]); | |
useEffect(() => { | |
const getBrands = async () => { | |
const { data } = await axios.get('/brands'); | |
setBrands(data); | |
}; | |
getBrands(); | |
}, []); | |
return [brands]; | |
} | |
const BrandsSidebar = () => { | |
const [brands] = useBrands(); | |
const [filter, setFilter] = useState(''); | |
return ( | |
<div> | |
<input type="text" value={filter} onChange={({ target }) => setFilter(target.value)} /> | |
{ | |
brands | |
.filter(({ name }) => name.toLowerCase().includes(filter.toLowerCase())) | |
.map(({ id, name }) => ( | |
<li key={id}> | |
<input type="checkbox" name='brands' id={id} value={name} /> | |
<span>{name}</span> | |
</li> | |
)) | |
} | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment