import { useState } from "react";
      import Select from "react-select";
      
      const options = [
        { value: "A", label: "A" },
        { value: "B", label: "B" }
      ];
      export default function App() {
        const [value, setValue] = useState("A");
        const handleChange = (value) => {
          setValue(value);    // here you set state value
        };
        return (
          <div className="App">
            <Select
              name="form-field-name"
              value={value}
              onChange={handleChange}
              options={options}
            />
            <button onClick={() => setValue(null)}>reset</button>
          </div>
        );
      }
      
      Python language logo

      How to react-select set value from state

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.