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

94
Vistas
Failure to update the variable value for the second time

I want to move an array value from a higher component to a lower order component with the click of a button.

In the lower order component, I get props like this:

 useEffect(() => {
            if (props.poolInfo) {
                setPoolInfo(props.poolInfo)
                diskSlot.push(props.poolInfo.disks_enc_slot)
                const firstِDiskSlot = Object.freeze(diskSlot);
                console.log(firstِDiskSlot );//[58:0,58:1] For the first time rendreing
                checkAllDiskInDriveGroup(props.poolInfo.disks_enc_slot, driveData)
            }
            return () => {
                setPoolInfo(false)
                setFormData({
                    count: {
                        options: [],
                        selectedValue: ""
                    },
                    disk: {
                        options: [],
                        selectedValue: ""
                    },
                })
            }
        }, [props.poolInfo])

Rendering a second time and adding value to the higher component:

console.log(firstِDiskSlot); //[58:0,58:1,58:3:58:4]

But I want to (firstِDiskSlot) The first value that is rendered should remain and not change because I need the first value:[58:0,58:1]

How do I freeze the initial value (firstِDiskSlot) that does not change a second time?

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

0

If you want to run it only once(on first prop value) then just remove dependency and leave empty array - useEffect(() => ..., []). If the problem is that first value might be the empty array, or undefined, then introduce stable constant with useRef and fill it in useEffect, but only if not previously filled, and like that you will have only first valid value in reference.

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