I have a store file which contains states. I defined user like this:
user: store.getState().user || { jobRecord: [] },
What I want is to push some job objects into user.jobRecord. The job object is defined like this:
job: store.getState().job || { title: '', company: '', start_date:
'', end_date: '' }
So first of all, I set some value into job object and then push it into user.jobRecord.
const joined = user && user.jobRecord;
store.setState({
user: {
...user,
jobRecord: [...joined, job],
},
});
By doing this, I get type error:
TypeError: joined is not iterable
I try this to set just one record in it:
jobRecord: [job],
but the result of jobRecord is:
[object Object]
Thank you a lot for considering my issue.
store.setStatedoes? Is it the same asuseState's setter method? But, this is absolutely true:joinedis not iterable. So it is not either an array or an object at that time. Try to log it and see if it isundefinedor something else.jobbut seeing thejobRecoredas[object Object]seems fine to me. Where do you check it? Developer console maybe?