Description
Hi,
I wrote a component Switch: https://codesandbox.io/s/m5oy50k649
When I use React and [email protected], getDerivedStateFromProps
will be called everytime before the render
method.
but when I use React and [email protected], 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 [email protected], It doesn't work as I expected.
Thanks for helping.