Home > Software design >  Select All options using React Select
Select All options using React Select

Time:09-29

I am using enter image description here

enter image description here

CodePudding user response:

And the selected item is an object not a string value:

const handlePostChange = (options) => {
    const postArray = [];
    options.map((option) => {
      if (option.value == 'select_all') {
        postValues = postValues.splice(1, (postValues.length - 1));
        postValues.map((option) => postArray.push(option));
      } else {
        postArray.push(option);
      }
    });

    setState({
      post_id: postArray,
    });
  };

CodePudding user response:

You forgot the value prop

<Select
    options={postValues}
    placeholder={"Select Post"}
    className="modal__input"
    isMulti={true}
    name={"post_id"}
    onChange={handlePostChange}
    value={state.post_id}
/>
  • Related