react-select icon indicating copy to clipboard operation
react-select copied to clipboard

How to obtain the previous value of the dropdown?

Open spunbell opened this issue 8 years ago • 2 comments

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?

spunbell avatar Nov 06 '18 22:11 spunbell

Looking to do this myself and finding no way of doing this

prashand avatar Feb 09 '21 08:02 prashand

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} />

ebonow avatar Feb 09 '21 14:02 ebonow