I've got a component, which has its props set by the parent component. The parent component changes regularly but the props of the child don't.
For some reason however the child keep rendering but I can't figure out why. To verify that the props and state are not changing I've added this function:
shouldComponentUpdate(nextProps, nextState) {
console.info(JSON.stringify(nextProps)+JSON.stringify(nextState));
console.info('NEXT PROPS ====================');
for (var n in nextProps) {
if (!nextProps.hasOwnProperty(n)) continue;
console.info(n + ' = ' + (nextProps[n] === this.props[n]));
}
console.info('NEXT STATE ====================');
for (var n in nextState) {
if (!nextState.hasOwnProperty(n)) continue;
console.info(n + ' = ' + (nextState[n] === this.state[n]));
}
return true;
}
This will print the following in the console:
{"autocomplete":null,"value":"","theme":1,"style":{"width":1426,"height":783},"label":"","description":null,"visible":false,"buttons":null,"inputType":null}{"visible":false,"answer":""}
NEXT PROPS ====================
autocomplete = true
value = true
theme = true
style = true
onClose = true
label = true
description = true
visible = true
buttons = true
inputType = true
NEXT STATE ====================
visible = true
answer = true
{"autocomplete":null,"value":"","theme":1,"style":{"width":1426,"height":783},"label":"","description":null,"visible":false,"buttons":null,"inputType":null}{"visible":false,"answer":""}
NEXT PROPS ====================
autocomplete = true
value = true
theme = true
style = true
onClose = true
label = true
description = true
visible = true
buttons = true
inputType = true
NEXT STATE ====================
visible = true
answer = true
So from one call to the next the state and props are strictly equal, yet the render() function of this component keep being called. Note that this shouldComponentUpdate() is just for testing - if I remove it, render() also keep being called under the same conditions.
Any idea what could be causing this?
false
fromshouldComponentUpdate
method. – Prakash Sharma