I have a multi select that i pass an object into the value property with the structure:
The select component looks like this:
<Select
multiple
value={entities}
onChange={handleChange}
input={<Input />}
renderValue={(selected) => (
<div className={classes.chips}>
{selected.map((value) => (
<Chip
key={value.entityId}
label={value.entityName}
className={classes.chip}
/>
))}
</div>
)}
>
{props.entityList.map((item, index) => (
<MenuItem key={item.entityId} value={item}>
{item.entityName}
</MenuItem>
))}
</Select>
when the select pops up it shows the entity name correct but does not show it as selected in the dropdown.
If i select this item in the drop down it adds another entry which has the same id and same name rather than removing the item that is already there, this newly added duplicate can be removed and is highlighted when selected so the functionality works somewhat.
I am storing entities in the state like so that comes in from a parent component:
Solution:
I have made sure that the same object is being used across the select, the initial object was not the same as the objects that where being assigned in the on Change function. this fixed my problem.
const [entities, setEntity] = React.useState(
props.entityList.filter((e) =>
props.assignedEntities.some((ae) => e.entityId === ae.entityId)
)
);


