0
votes

Recently i've refactored my Checkbox component to use the new getDerivedStateFromProps static method instead of the deprecated componentWillReceiveProps.

Now i'm experiencing some issues:

1. I had to save another previousValue in the component state and compare it each time with the new values, coming from state or props - (otherwise it won't work, since getDerivedStateFromProps is invoked upon each update, also state change).

2. getDerivedStateFromProps is called 4 times per checkbox change which seems like a waste...

What am i missing here?

code example

1
Fixed by removing inner state and getDetivedStateFromProps and using only the parent's state. - nabnaf

1 Answers

0
votes

Fixed by removing inner state and getDetivedStateFromProps and using only the parent's state. fixed-code