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

146
Vistas
React setState hook's previous param object gives inconsistent values

I'm using a useEffect hook to trigger a setState update. I'm getting some strange and inconsistent behaviour from the previous param:

    useEffect(() => {
        setCurrentPicturesObject((existing) => {
            const clone = {...existing}
            console.log({
                existing,
                existingdotNocolor: existing.nocolor,
                selectedColorState,
                selectedColorArray: existing["nocolor"],
                clone
            });
            return existing
        });
    }, [selectedColorState]);

So you'd expect that the clone of the object would return an object with the same keys and values, right? Not here:

screenshot of console log

Somehow existing goes from being an object with a nocolor prop with an array of two strings, to switching to an array with one string. Similarly when I try to access the nocolor prop it only returns an array with one string.

I can't understand. existing changes as soon as I try to access it with anything other than simply console logging it directly?

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

0

Not entirely sure on the details, but essentially it seems that the console is logging a live view of the object, which is a static string. More info in this answer.

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