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

175
Vistas
React: pull dependent data from custom hooks into component without re-rendering when non-dependent data changes

If a component uses some data from a custom hook and if the custom hook also contains data (local/global) which is not consumed by the above component, then the component re-renders even when the non-dependent data changes (references for non-primitive types). Is there a way to prevent this?

Example code:

useTest.hook.js

export default function useTest() {
  const {
    consumedData, nonConsumedData
  } = useSelector(state => state.Data);

  return {
    consumedData,
    nonConsumedData
  }
}

Component.js


export default function Component() {
    const {consumedData} = useTest();
    return <div>{consumedData}</div>;
}

Here Component re-renders when nonConsumedData changes ( or even when state.Data changes ). nonConsumedData might be consumed by some other component. Is there a way to stop the re-render in such cases?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use memoization to avoid re-rendering components (if re-rendering affects performances).

With function based components, just use React.memo()

const MyComponent = React.memo(function MyComponent(props) {
  /* render using props */
});

More information here: https://reactjs.org/docs/react-api.html#reactmemo

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