Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

141
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda