Categories
React Answers

How to disable options with React Select and JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *