For example we have such state:
state = { hasSomething: true, anotherKey: '', ... }
and we should update only 'hasSomething':
static getDerivedStateFromProps(nextProps) {
if (nextProps.accessKey === 'admin') {
return {
hasSomething: false,
};
}
return null;
}
do we need to destruct the prevState when we return new state? for example like this:
static getDerivedStateFromProps(nextProps, prevState) {
if (nextProps.accessKey === 'admin') {
return {
...prevState,
hasSomething: false,
};
}
return null;
}
or we don't need it? i checked the console.log(this.state) and it returns the whole local state if im not make a prevState destructing.
i can't find this information in official react documentation :(
P.S. this logic just an example :)