onChange triggered in react-select even when selecting the same option #6050
Unanswered
Balaji1202
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm running into an issue with the react-select component where the onChange event is fired even when the user selects the same option that's already selected. Ideally, I want onChange to be triggered only when the selected value actually changes.
Here’s a minimal reproducible example on CodeSandbox:
👉 React Select Example
In the example, I’ve added a console.log and a debugger in the onChange handler to show that the function is called even when the same option is clicked repeatedly.
Is this actually an issue with react-select, or is there a clean way to prevent onChange from firing unless the selected value is different from the current one that will work for both multiselect and singleselect?
Any guidance would be appreciated. Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions