-
-
Notifications
You must be signed in to change notification settings - Fork 533
Description
Hello, I noticed that react-calendar notifies parent component about various events via .setState() callback.
E.g.
react-calendar/src/Calendar.jsx
Line 310 in be7c443
| this.setState({ value: nextValue }, callback); |
The problem is that.setState() callback is called after react finishes real DOM updates. That means, changes from parent component will cause another update cycle. Also parent component might remove calendar in response to event entirely making previous update completely useless.
You can verify such behaviour via DevTools profiler
In the screenshot above all the work before Lifecycle hook scheduled a cascading update is completely useless and causes substantial delay.
Another reason not to use .setState() for parent callbacks is to avoid crashing entire app in case parent event handler erroneously raises exception.
