When react-switch runs an onChange callback which unmounts the component (e.g. conditional render on toggle inside the parent component), a React warning appears:
Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.
This is caused by this.setState being called after an onChange which caused an unmount. This PR adds mount/unmount tracking and prevents those setState that would run after unmount.
When react-switch runs an onChange callback which unmounts the component (e.g. conditional render on toggle inside the parent component), a React warning appears:
This is caused by this.setState being called after an onChange which caused an unmount. This PR adds mount/unmount tracking and prevents those setState that would run after unmount.