Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

101
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda