-
Notifications
You must be signed in to change notification settings - Fork 25
Description
Hi,
I wrote a component Switch: https://codesandbox.io/s/m5oy50k649
When I use React and ReactDom@16.4.1, getDerivedStateFromProps will be called everytime before the render method.

but when I use React and ReactDom@15.0.0, and with this polyfill, getDerivedStateFromProps is called just before the first render, as my example shows. This is not what I expected.

getDerivedStateFromProps is invoked right before calling the render method, both on the initial mount and on subsequent updates
Here's what I want:
Switch has a state checked, and a prop checked as well.
if <Switch />, the component can work because it has it's own state checked;
if <Switch checked />, the component will never change state, because before every render, getDerivedStateFromProps will reset the components' checked.
But when React and ReactDom@15.0.0, It doesn't work as I expected.
Thanks for helping.