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

139
Vistas
How to access prevProps' in React Hooks when prevProps' data type is object or array

My question is this, I'm having an array I need to monitor its change in my componentDidUpdate lifecycle, now I'm trying to rewrite the component in hooks, I'm having issue in doing so in hooks, a lot of the solutions I found on the internet suggests to create a customized usePrevious hook like this

    const usePrevious = value => {
      const ref = useRef();
      useEffect(() => {
        ref.current = value;
      });
      return ref.current;
    };

But I found that this hook can only deal with primitive data type, it doesn't seem to work with object or array...

  componentDidUpdate(prevProps) {
    if (!_.isEqual(myArray, prevProps.myArray)) {
      // do something...
    }
  }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

From what you're saying I think using a useEffect hook that has the prop you want to watch for as dependency and the logic inside should do the trick, you can check the React Docs for a more detailed explanation, but basically, it would look like this

useEffect(() => {
  // code to run when it changes
}, [yourVar]);
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