Skip to content

Instantly share code, notes, and snippets.

@hesan-aminiloo
Created July 15, 2022 10:25
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 hesan-aminiloo/9d014cf42cd99a30dd055b2f65c4f50e to your computer and use it in GitHub Desktop.
Save hesan-aminiloo/9d014cf42cd99a30dd055b2f65c4f50e to your computer and use it in GitHub Desktop.
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