Created
July 28, 2021 03:46
-
-
Save Risyandi/414fc8d76b1fd2cd3e7614f01e2fcc0f to your computer and use it in GitHub Desktop.
line code for clear react select
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useRef } from "react"; | |
import Select from "react-select"; | |
export default function App() { | |
const selectInputRef = useRef(); | |
const onClear = () => { | |
selectInputRef.current.select.clearValue(); | |
}; | |
return ( | |
<div className="App"> | |
<h1>Select Gender</h1> | |
<Select | |
ref={selectInputRef} | |
options={[ | |
{ value: "male", label: "Male" }, | |
{ value: "female", label: "Female" } | |
]} | |
/> | |
<button onClick={onClear}>Clear Value</button> | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment