react-select
react-select copied to clipboard
How to obtain the previous value of the dropdown?
Hi, I need to handle the previous value of the dropdown before the onChange function is called and the value is changed. How can I get this to work in this library?
Looking to do this myself and finding no way of doing this
Greetings @prashand ,
You'd likely want to make it a controlled input with the value.
const [ value, setValue ] = useState();
const onChange = newValue => {
// value is your previous value
// newValue is your new value
// Do comparison stuff and then set new value
setValue(newValue);
}
return <Select value={value} onChange={onChange} {...otherProps} />