O
O
Oleg Drapeza2017-08-24 15:49:58
JavaScript
Oleg Drapeza, 2017-08-24 15:49:58

Optimizing React components with children property?

Good afternoon!
When creating layout components, I encountered the following problem - if the layout component accepts child components as children, and its shouldComponentUpdate method is called - each time the current and new props.children are not equal to each other (even when these children are actually the same).
Code Example
When we click on the "Change Color" button, we change the state of the main App component, which causes a redraw of its child Layout component, whose children have not changed.
What is the reason children are always not equal to each other, and how can you avoid these redraws of the simplest static component, other than implementing your own shouldComponentUpdate (not convenient with a large number of incoming properties)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
davidnum95, 2017-08-24
@davidnum95

class Layout extends React.PureComponent?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question