child component state like:
interface State {
data: { x: number; y: string };
}
// initial in constructor
this.state = {
data: {
x: 10,
y: 'sss',
},
};
when do setState
like:
const { data } = this.state;
data.x += 10;
this.setState({ data });
nextState
always equal this.state
in shouldComponentUpdate
, console log in shouldComponentUpdate
is:
next: {"data":{"x":20,"y":"sss"}}
this: {"data":{"x":20,"y":"sss"}}
I want to render child component only when child after setState
, instead of parent component render.
so, when parent component render, how to avoid child re-render
update: