Search code examples
reactjsmaterial-uireact-select

React-select multi not working the way it's defined in the documentation


I am using react-select to make a searchable dropdown menu. And it's working fine until you actually select an option, then it just throws an Each child in an array or iterator should have a unique "key" prop. error, doesn't remove the option you have picked and doesn't show what you have picked so far. My options are an array with objects {value: crew.id, label: crew.code}, and here is my Select component

<Select
    isMulti
    name='teamIdsFilter'
    menuPosition='fixed'
    options={crewOptions}
    value={teamIds}
    placeholder='Nepasirinktas'
    onChange={event => this.handleTeamIdsSelect(event)} />

And my handleTeamIdsSelect event handler

handleTeamIdsSelect = (event) => {
    if (event) {
        const selectedCrew = event.map(crew => crew.value);
        this.setState({teamIds: selectedCrew});
    }
};

Solution

  • Try using multi instead of isMulti. This will fix the problem.

    <Select
        multi
        name='teamIdsFilter'
        menuPosition='fixed'
        options={crewOptions}
        value={teamIds}
        placeholder='Nepasirinktas'
        onChange={event => this.handleTeamIdsSelect(event)} />