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

97
Views
Prevent rerendering when specific prop changes

I am having a reusable component which takes an editable prop which can be toggled from outside. The problem is that whenever that toggle is activated the whole component rerenders including API calls which should be only called once. How can i prever rerender if the specific prop editable changes? Or what is the way to solve this issue?

What i would like to obtain is to get the API call only once in the component no matter how many times the editable prop changes. How can i achieve this?

Code bellow:

export const EditableTableList: React.FC<EditableTableListProps> = React.memo(({ columns, editEnabled, keyName, getData, sendChangeToParent }) => {
...
// THIS RERENDERS EVERYTIME EDITABLE CHANGES
  useEffect(() => {
    const getTableData = async () => {
      setLoadedData(false);
      setOriginalData(await getData());
      setLoadedData(true);
    }

    getTableData();
  }, [getData]);
...
}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

getData() will re-render every time the parent component will, you could send it as a useCallback function expression so it would retain the same identity even if parent re renders.

about 4 years ago · Juan Pablo Isaza Report

0

The effect is executed again only because your getData function is changing - maybe not its content but definitely the instance/reference.

You'll have to memoize it in your parent component, for example using useCallback. If you provide the parent component I could give you an example.

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!