Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

109
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!