Created
July 15, 2022 10:25
-
-
Save hesan-aminiloo/9d014cf42cd99a30dd055b2f65c4f50e 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 BrandsSidebar = () => { | |
const [brands, setBrands] = useState([]); | |
const [filter, setFilter] = useState(''); | |
useEffect(() => { | |
const getBrands = async () => { | |
const { data } = await axios.get('/brands'); | |
setBrands(data); | |
}; | |
getBrands(); | |
}, []); | |
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