Closed maxijonson closed 5 years ago
I don't quite understand what you mean. If the component is unmounted, then surely you wouldn't be able click the handle since the component wouldn't exist?
Feel free to edit this sandbox to show the problem if you think it would help.
My bad, I found out that the component that had the react-switch was causing this error. Although the error did come from $onDragStop from react-switch, I am unable to reproduce it... I think I just stumbled on a very unique case.
In my case, the switch was responsible for switching between a light and dark theme. Switching themes would change the color of almost every component, including the one with the react-switch and the react-switch itself, which would trigger a re-render. The error would only show up when I clicked on the handle, which would immediately change the theme and I guess the switch was still in $onDragStop
.
Anyways, once I found out that the parent component was causing this, I fixed it and haven't seen the error since...
Ok. Glad it worked out for you.
@maxijonson Hello, I'm also seeing this issue in my code. Could please tell me how you fixed it? Thank you so much! I guess a straightforward solution is just moving the Switch to somewhere that we will never rerender. But in my case I can't do it due to the UI layout restrictions.
Thank you!
@foolhb The error was in the component wrapping the switch. Unfortunately, I don't rememberexactly what it was, but it had to do with state changing and triggering a render. Sorry I can't be of more help..
@maxijonson Thank you. So it looks like we can't reset the Switch's state and re-render the whole component at the same time, right? I guess you might have moved the Switch to somewhere else.
Thank you!
When clicking on the handle, if the component is unMounted, it will call setState in $onDragStop. I have tried adding a
componentWillUnmount
and remove listeners, but that did not do the trick...