see which one you inherit. Inheriting component can be modified directly. It is not possible to inherit purecomponent
first of all, this method of writing is not recommended, but more recommended is the way of writing immutable, for example:
var items = this.state.items;
this.setState({
items: items.map(item => ({...item, ...{status: 'doing'}}))
});
Why is it not recommended to modify it directly?
There are two reasons for
:
1. Performance issues
this way of directly changing the original object makes it impossible for react to optimize it, so
has potential performance problems
.
2. It is difficult to locate the problem
if you use purecomponent, you will find that the status cannot be updated directly. The reason for
is that purecomponent rewrites the SCU,SCU by directly judging the reference difference between state and props, so it will
return false, so that render cannot run
.
this method is not officially recommended, but many people use
if you are worried, you can use immutable, or directly get a copy of the object array and change it
.
setState ()