Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

112
Views
prevent re render in child component in react js

I have a counter app. I need to prevent re-render component. I want to execute Childcompnent only when I clicking on update, but here it is executing both time when I click count or update.

import { useCallback, useMemo, useState } from "react";

export const App = () => {
  const [count, setCount] = useState(0);
  const [updatecount, setUpdateCount] = useState(0);

  const incCount = () => {
    setCount(parseInt(count) + 1);
  };

  const updCount = useCallback(() => {
    return setUpdateCount(parseInt(updatecount) + 1);
  }, [updatecount]);

  return (
    <>
      <button onClick={incCount}>count</button>
      <button onClick={updCount}>update</button>
      <Childcompnent count={count} />
      <p>{updatecount}</p>
    </>
  );

};

export default App;

export function Childcompnent({ count }) {
  console.log("pressed");
  return <p>{count}</p>;
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Wrap your Childcompnent in React.memo:

const Childcompnent = React.memo(({ count }) => {
  console.log("pressed");
  return <p>{count}</p>;
});

Here is the sandbox:

Edit serverless-wood-ro6iek

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!