Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

98
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda