Invalid Attempt to Spread Non-Iterable Instance

TypeError: Invalid attempt to spread non-iterable instance

This is because it is a runtime error, not a "compile time" error.

Is there a line number associated with the error? Based on the question being about the spread operator I'll assume it's this line: newArticlesData=[...prevData,...response.data]. I assume your prevData is iterable, but is your response data? Try newArticlesData=[...prevData, response.data]?

Here's an example of invalid spread operator use:

function trySpread(object) {  let array;  try {    array = [...object];    console.log('No error', array);  } catch(error) {    console.log('error', error);  }}
// errortrySpread({});trySpread({foo: 'bar'});trySpread(4);
// no errortrySpread([]);trySpread(['foobar']);trySpread('foobar');

Invalid attempt to spread non-iterable instance with django REST and Vue.js

It looks like the data returned from the API doesn't have a property called results which is undefined when you try to spread it (only arrays and object support that spread operator), so you should do :

 this.reviews.push(...data)

React "TypeError: Invalid attempt to spread non-iterable instance"

You're forgetting to spread your new value for favoriteBeers into an array:

setFavoriteBeers([
...favoriteBeers,
beers.find(beer => beer.id === id)
])


Related Topics



Leave a reply



Submit