Skip to content

Instantly share code, notes, and snippets.

@Risyandi
Created July 28, 2021 03:46
Show Gist options
  • Save Risyandi/414fc8d76b1fd2cd3e7614f01e2fcc0f to your computer and use it in GitHub Desktop.
Save Risyandi/414fc8d76b1fd2cd3e7614f01e2fcc0f to your computer and use it in GitHub Desktop.
line code for clear react select
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