How to disable options with React Select and JavaScript?

Sometimes, we want to disable options with React Select and JavaScript.

In this article, we’ll look at how to disable options with React Select and JavaScript.

How to disable options with React Select and JavaScript?

To disable options with React Select and JavaScript, we set the isDisabled property to true.

For instance, we write

import Select from "react-select";

const ReactSelect = () => {
  const options = [
    { label: "a", value: "a", isDisabled: true },
    { label: "b", value: "b" },
  ];

  return <Select name="mySelect" options={options} />;
};

to set the options prop to the options array.

In options, we set isDisabled to true to disable the first option.

Conclusion

To disable options with React Select and JavaScript, we set the isDisabled property to true.