fraserxu / react-dropdown

🔽 A dead simple dropdown component for React
http://fraserxu.github.io/react-dropdown/
MIT License
670 stars 251 forks source link

How to reset default value after option has been selected. #212

Closed BigDaddyKahuna closed 1 year ago

BigDaddyKahuna commented 3 years ago

It appears that once you select an option from the dropdown, that value remains selected. I would like to reset the value to the default value after capturing the user's selection. Is this possible?

ordidxzero commented 3 years ago
const [otherValue, setOtherValue] = useState('');
const [value, setValue] = useState<string | undefined>(undefined);
  useEffect(() => {
    setValue(undefined);
  }, [otherValue]);

...

<Dropdown value={value} />
freder commented 1 year ago

<Dropdown value={undefined} /> does not seem to work. – selecting an option will still update the state.