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

115
Views
how to add array to an object as property?, like object of more than 1 property and one of the property is array

enter image description here IMAGE 1

enter image description here IMAGE 2

enter image description here IMAGE 3

so initially in image 1 i have this function dispatch, when it gets called it passes two argument "type" and "item".

Now the problem is, in image 2 i need to return the item to state object and store it in that state and every time that dispatch function gets called new values of item should be added to state but but......the state object is not retaining the item value, it is removing the previous value and passing the new value so i am receiving only the last value.

I need to map that item property later and for that i need it to be an array, so it should be like:

const state = {
count: 1,
item: [product1, product2, product3, ......]
}

Note: product is an object

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

It should be something like

return {
  ...state,
  count : state.count + 1,
  item : [...state.item, action.item]
}
about 4 years ago · Santiago Trujillo 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!