I'm learning React and I'm trying to create a dynamic Dropdown select. I'm importing the data from fetched API successfully from another component. I want to populate select option by category from the fetched data, which is an array of a single string either 'women', 'men' or 'kids' . What I want, is to have initially all data listed, to have 3 options for category strings and list only matching products according to the onChange event.
Now when I click to the select the whole app renders and can't see the bug.
Any help will be appreciated
Here is how API data looks like:
[
{
categories: [
'women'
],
variants: [
'white',
'black',
'green'
],
sizes: [
38,
39,
40
],
_id: '5f8edf08880a821cb8757d8a',
name: 'Nike Air',
description: 'Tennis court levitating sneaker',
img: 'https://source.unsplash.com/user/erondu/PGTO_A0eLt4',
price: 100,
__v: 1
}
]
Category component
import React, { useState } from 'react'
const Categories = ({ categories }: any) => {
const [category, setCategory] = useState('')
console.log('category', category)
return (
<>
<select
value={category}
onChange={(e) => setCategory(e.target.value)}
>
<option value="">Select</option>
{categories && categories.map((option: any) => (
<option key={option._id}
value={option.categories}
>
{option.categories}
</option>
))}
</select>
</>
)
}
export default Categories
console.logoutput. Post something that is actually copyable/usable.