in Technology by
How to prevent re-renders in React?

1 Answer

0 votes
by

Reason for re-renders in React:
Re-rendering of a component and it’s child components occur when props or state of the component has been changed.
Re-rendering components that are not updated, affects the performance of an application.

How to prevent re-rendering:
Consider the following components:

class Parent extends React.Component {
 state = { messageDisplayed: false };
 componentDidMount() {
   this.setState({ messageDisplayed: true });
 }

 render() {
   console.log("Parent is getting rendered");
   return (
     <div className="App">
       <Message />
     </div>
   );
 }
}

class Message extends React.Component {
 constructor(props) {
   super(props);
   this.state = { message: "Hello, this is vivek" };
 }  
 render() {
   console.log("Message is getting rendered");
   return (
     <div>
       <p>{this.state.message}</p>
     </<span style="-webkit-font-smoothing:subpixel-antialiased; border:0px; box-sizing:border-box; color:#007020; font-family:Helvetica,Arial,Sans-serif; font-size:15px; margin:0px; padding:0px; text-rendering:optimiz

Related questions

0 votes
    I have minified all my js files using require, but require created a minified js file( main.min.js ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
0 votes
    I have minified all my js files using require, but require created a minified js file( main.min.js ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 16, 2022 in Education by JackTerrance
0 votes
    I am using Python 2.6.6 and SQLAlchemy 0.6.6 to handle a one to many relationship in my database ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 4, 2022 in Education by JackTerrance
0 votes
    I want making multi-bluetooth from Android studio. I found multi-bluetooth java code libraries. but I am ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 3, 2022 in Education by JackTerrance
0 votes
    VS 2008 / C# / MS 2007 I have a Saved Import Feature in Access Database which invokes ODBC Connection ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    How you can be avoid or prevent ARP poisoning?...
asked Feb 20, 2021 in Technology by JackTerrance
0 votes
    What is a Pharming attack and how to prevent it?...
asked Feb 17, 2021 in Technology by JackTerrance
0 votes
    What is SQL injection and how to prevent it?...
asked Feb 16, 2021 in Technology by JackTerrance
0 votes
    How to prevent ARP poisoning?...
asked Feb 16, 2021 in Technology by JackTerrance
0 votes
    What is MAC flooding and how to prevent it?...
asked Feb 16, 2021 in Technology by JackTerrance
0 votes
    How do you prevent a class from being inherited?...
asked Dec 31, 2020 in Technology by JackTerrance
0 votes
    I'm working on a program that displays a list from an SQFlite table. The future for the snapshot ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 30, 2022 in Education by JackTerrance
0 votes
    My CPU usage is 100% most of the the time in Windows Server 2008-R2 with my own vps, vmware, ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    This question's answers are a community effort. Edit existing answers to improve this post. It is not ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    I'd like to ensure my RAII class is always allocated on the stack. How do I prevent a class from ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
...