I am using react and react-dom version "^16.12.0";
I would like to use the material ui multi selectbox with chips inside of my react js project. Therefore I need to map my array into the list as an <MenuItem>. I am getting the
Objects are not valid as a React child (found: object with keys {value, label}).If you meant to render a collection of children, use an array instead.
I have already tried the Object.keys(races).map and Object.entries(races).map ``` and I also tried to put this into a const inside of render, but I'm always getting the same error...
Here's the snippet which isn't working (inside of a calss component):
<Grid item xs={6}>
<Select
name="dogName"
multiple
id="select"
value={this.state.dogName}
onChange={this.handleChangeMultiple.bind(this)}
input={<TextField />}
renderValue={(selected) => (
<div style={{display: 'flex',flexWrap: 'wrap',}}>
{selected.map((value) => (
<Chip key={value} label={value} style={{margin: 2,}} />
))}
</div>
)}
>
{races.map((name) => (
<MenuItem key={name.value} value={name.label} >
{name}
</MenuItem>
))}
</Select>
</Grid>
And here is the array (in it's own '.js' file, imported as import {races} from './helper/dograces.js';):
export const races = [
{value: 'unknown', label: 'unknown'},
{value: 'B1', label: 'Bulldog'},
{value: 'P1', label: 'Pitbull'},
...
]
Please help .. I really don't understand where the problem is..!
Best regards!