FrontendChallenges is a collection of frontend interview questions and answers. It is designed to help you prepare for frontend interviews. It's free and open source.
difficulty: medium
title: React re-render
template: react
tags: react, performance
Question
We have 3 components: App at the top, which renders Counter, which renders BigCountNumber and a simple Decoration component. Due to how React works, when the state count changes, the Decoration is also re-rendering despite of the fact it is not dependent on the count state since it is not receiving count as prop.
How can we avoid re-render of Decoration component?
Info
Question
We have 3 components: App at the top, which renders
Counter
, which rendersBigCountNumber
and a simpleDecoration
component. Due to how React works, when the statecount
changes, theDecoration
is also re-rendering despite of the fact it is not dependent on thecount
state since it is not receiving count as prop. How can we avoid re-render of Decoration component?Template
styles.css
App.jsx
index.jsx
public/index.html
Counter.jsx
Decoration.jsx
BigCountNumber.jsx