Reputation: 125
I have an object that has an array with it. Something like this:
const [data, setData] = useState({ jobs: [] });
Now I am fetching data from an API & I need to add that fetched information to the jobs array. How do I do that? When I do this: setData(newData)
it is not going into that jobs array.
Please help!
Upvotes: 0
Views: 109
Reputation: 2145
You need to wrap the result in an object and use then jobs key.
setData({ jobs: newData })
Upvotes: 1