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

114
Vistas
Strange behaviour when pushing to imported array in React

I am pushing the same object to both a local array and an imported array in React, as follow:

import { EVENTS_DRAFT } from "../../store/stateless/event_draft";
...
        EVENTS_DRAFT.push({ //<=== imported array
          howmanykeys: "random string",
        });
        
        let EVENTS_DRAFT_LOCAL = ['EVENTS_DRAFT_LOCAL'];
        EVENTS_DRAFT_LOCAL.push({
          howmanykeys: "random string",
        })

As per console.log below, the EVENTS_DRAFT_LOCAL works as expected, but the imported EVENTS_DRAFT gives this "broken" array object with a seemly length of 2, but then has really 5 items when expanded.

enter image description here

If I push a string instead of an object, both arrays works as expected. I cannot reproduce this in a regular node app, so I suspect it may have to do with React's diffing algorithm, but really not sure.

getCreateTasks.js

import { EVENTS_DRAFT } from "../../store/stateless/event_draft";

const getCreateTasks = (calDate) => {
  EVENTS_DRAFT.push({
    howmanykeys: "random string",
  });

  let EVENTS_DRAFT_LOCAL = ["EVENTS_DRAFT_LOCAL"];
  EVENTS_DRAFT_LOCAL.push({
    howmanykeys: "random string",
  });

  console.log("EVENTS_DRAFT_LOCAL:");
  console.log(EVENTS_DRAFT_LOCAL);

  console.log("");

  console.log("EVENTS_DRAFT:");
  console.log(EVENTS_DRAFT);
};

export default getCreateTasks;

event_draft.js

export const EVENTS_DRAFT = ['EVENTS_DRAFT'];

full code on github here. https://github.com/SeanLuo-FSWD/RTFEJS.git

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