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

95
Views
nested object disappears after function call

I've been trying to add an object inside an object, but this one disappears after I call a function:

I have one object 'item'

  const item = {
    id,
    type: 'instance',
    parent_id: null,
  }

I then call an API to get an other object of datas.

try {
 const res = await api.getData()
 console.log(res.data) // return { key1: value1, key2: value2 }
} catch(error) {
 console.log(error)
}

I add those key/value pair to an 'instance_setting' object inside item.

item.instance_setting = res.data

console.log(item) // return { id: 'xxx', type: 'instance', 'parent_id': 'xxx', instance_setting: {key1: value1, key2: value2 }}

So far all is doing fine.

Then I call a function 'MUTATE_DATA' to add this object into my state, which trigger the unexpected behavior. Here is the whole code:

const MUTATE_DATA = (item) => {
  state.menuItems.push(item)
  state.newItems.push({ id: item.id })
}

const useAddInstance = async (id) => {

  const item = {
    id,
    type: 'instance',
    parent_id: null,
  }

 try {
 const res = await api.getData()
 item.instance_setting = res.data

 MUTATE_DATA(item)
 console.log(item) // return { id: 'xxx', type: 'instance', 'parent_id': 'xxx'}

} catch(error) {
 console.log(error)
}

You can see in the console.log(item) my object instance_setting disappeared.

I know the line making problem is

state.newItems.push({ id: item.id })

but I do not understand why this would make this nested object disappear.

Thanks for your help!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As Bergi stated, a computed property somewhere else in the code was deleting the instance_setting into state.newItems

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