tbleckert / react-select-search

⚡️ Lightweight select component for React
https://react-select-search.com
MIT License
676 stars 147 forks source link

`onChange` missing in headless mode #74

Closed deodad closed 4 years ago

deodad commented 4 years ago

Thanks for the great library.

I'm running into an issue using the useSelect hook where I'm unable to provide an onChange function for the when the value changes. I tried passing it into useSelect but I see it's not a supported option.

Is this something that can be added or is there another preferred way to fire a function after a change in headless mode?

tbleckert commented 4 years ago

This was fixed in v1.0.4, you can now pass a function that is called on change:

useSelect({
    ...
    onChange: console.log,
});

The selected value is also available in the snapshot returned by the hook. So you could use the useEffect hook to run code when that changes. Like this:

useEffect(() => {
    // value changed
}, [snapshot.value]);