I would like to know if a React component extending React.Component
deeply compares an object when trying to decide if it needs to rerender.
For instance, given
const Foo = ({ bar }) => {
return <div>{bar.baz}</div>
}
class App extends React.Component {
constructor() {
super()
this.state = { bar: { baz: 1} }
}
render() {
return <Foo bar={this.state.bar} />
}
}
If inside App
, the state bar
changes to {baz: 2}
, does <Foo />
deeply compare the previous prop bar
and the newly received prop?
Incidentally, the docs for PureComponent says
Extend PureComponent ... Or, consider using immutable objects to facilitate fast comparisons of nested data.
But does not go into much more details. Any ideas?