Invalid Attempt To Spread Non Iterable Instance

Invalid Attempt To Spread Non Iterable Instance




⚡ ALL INFORMATION CLICK HERE 👈🏻👈🏻👈🏻

































Invalid Attempt To Spread Non Iterable Instance

Sign up or log in to customize your list.

more stack exchange communities

company blog


Stack Overflow for Teams
– Start collaborating and sharing organizational knowledge.



Create a free Team
Why Teams?



Asked
1 year, 5 months ago


Modified
1 year, 5 months ago



Sorted by:


Reset to default





Highest score (default)


Trending (recent votes count more)


Date modified (newest first)


Date created (oldest first)




7,188 4 4 gold badges 21 21 silver badges 59 59 bronze badges


Stack Overflow

Questions
Help



Products

Teams
Advertising
Collectives
Talent



Company

About
Press
Work Here
Legal
Privacy Policy
Terms of Service
Contact Us
Cookie Settings
Cookie Policy



Stack Exchange Network



Technology




Culture & recreation




Life & arts




Science




Professional




Business





API





Data






Accept all cookies



Customize settings


Find centralized, trusted content and collaborate around the technologies you use most.
Connect and share knowledge within a single location that is structured and easy to search.
I am using an API to render data in cards, and each card has a heart icon which when clicked, will change the card's state to favorite. Each card has a corresponding modal (I'm using [material ui modal][1] and ) that has the heart icon as well and I need to do it so that when the heart on the modal is clicked, both the modal and the its corresponding card get the favorite state.
Initially I changed the state in the card and the modal components, and had a piece of code that looked like this:
The previous block of code handles the state, and the following is part of the returned html:
Now that I need to match the modal's state with the initial card's state, I have moved the state to the App component and I want to create an array to push the favorite items inside and trying to use the item's id:
Now when I click the heart on a card all the cards become favorite, and when I click the heart I'm getting "TypeError: Invalid attempt to spread non-iterable instance".
You're forgetting to spread your new value for favoriteBeers into an array:
Thanks for contributing an answer to Stack Overflow!

By clicking “Post Your Answer”, you agree to our terms of service , privacy policy and cookie policy

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Site design / logo © 2022 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2022.9.7.42963


By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy .


[Solved]-TypeError: Invalid attempt to spread non-iterable instance-React Native
function trySpread(object) {
let array;
try {
array = [...object];
console.log('No error', array);
} catch(error) {
console.log('error', error);
}
}

// error
trySpread({});
trySpread({foo: 'bar'});
trySpread(4);

// no error
trySpread([]);
trySpread(['foobar']);
trySpread('foobar');
let newMyObj = {...myObj} // this will works perfectly fine.Iteration is possible above way.

fetch(url, {
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
'x-sh-auth': userToken || userStoredToken,
},
})
.then(response => response.text())
.then(async responseText => {
let responseData = JSON.parse(responseText);
console.log('responseData HomeWhatsNewUser', responseData);
if (responseData.code == 200) {
setpageNumberwhatsnewap(pageNumberwhatsnewapi + 1);
setiSloding(false);
setWhatsNewAPiUser({...WhatsNewAPiUser, ...responseData});
// setWhatsNewAPiUser(responseData);
// setLoadMoreNewUserApiLink(responseData.load_more_url);
} else {
if (responseData.message === 'Your are un authorize') {
await AsyncStorage.removeItem('@userData');
await AsyncStorage.removeItem('@userToken');
props.navigation.navigate('HomeScreen');
}
Toast.show({
text1: responseData.message,
});
setiSloding(false);
}
})
.catch(error => {
setiSloding(false);
console.log(error, 'error from APi');
});
};

if(propSearch=="" || propSearch==null && this.state.currentPage!=1 && refresh!=true){
newData=[...this.state.articlesData,...response.data]
}
else{
newData=response.data
}

{
"presets": [
"module:metro-react-native-babel-preset"
],
"plugins": [
"syntax-trailing-function-commas",
"@babel/plugin-transform-flow-strip-types",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-regenerator",
"@babel/plugin-transform-async-to-generator",
"@babel/plugin-transform-runtime",
[
"@babel/plugin-transform-spread",
{
"loose": true
}
]
],
"sourceMaps": true
}


Copyright 2022 www.appsloveworld.com . All rights reserved.

    console.log( 'No error' , array);
    console.log( 'error' , error);
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:
Save my name, email, and website in this browser for the next time I comment.
Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

[Solved]-TypeError: Invalid attempt to spread non-iterable instance. In set an Array into state in class component-React Native
this.setState(({details}) => {return [...details, additional]})

Copyright 2022 www.appsloveworld.com . All rights reserved.

Naughty America Latina Porn
Hd Massage Porn Video
Nudist Miss Junior Beauty Pageant

Report Page