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

143
Vistas
Object key of past elements of states get rewritten when new state added to array of states

I have this strange issue that when I set a new state using spread operator only one object key get rewritten.

useEffect(() => {
    props.setCanvas([...props.canvas, {
                    block: 1,
                    innerBlock: !props.canvas.length ? 1 : (innerBlockChange(props.drop.blockType, props.canvas[props.canvas.length - 1].blockType) ? props.canvas[props.canvas.length - 1].innerBlock + 1 : props.canvas[props.canvas.length - 1].innerBlock),
                    blockType: (props.drop.blockType == 'center') ? 'center' : 'double',
                    class: 'placeholders',
                    position: props.drop.blockType,
                    size: 'regular',
                    entity: props.drag.element, // this one get rewritten
                    index: !props.canvas.length ? 1 : props.drop.main.querySelector('section.block:not(.mockup)').querySelectorAll('.placeholders').length + 1,
                    indexOfType: props.canvas.filter(el => el.entity = props.drag.element).length + 1,
                    connections: [],
                    properties: [],
                    comments: [],
                    embed: false
                }]);
},[props.drag]);

The entity key don't keep the stored value and changes when setState get executed again.

For example if for the first element it set to A When the setState run for second time with new entity value of B the first element of canvas states changes to B as well.

I tried to use a completely separate state (not the props.drag) for it but the issue still exist.

about 4 years ago · Juan Pablo Isaza
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