TypeError: Invalid attempt to spread non-iterable instance
After compiling to android and downloading via Store I get the error:
"TypeError: Invalid attempt to spread non-iterable instance"
But using "react-native run-android" creates no error message therefor I can't find a good way to debug it.
fetch(url)
.then(response => response.json())
.then(response => {
if (this._mounted) {
// let dataSource = this.state.articlesDataSource.cloneWithRows(response.data || )
//var rowCount = dataSource.getRowCount();
var rowCount = Object.keys(response.data).length;
if (refresh == true) {
prevData = {};
} else {
prevData = this.state.articlesData;
}
if (propSearch == "" || propSearch == null) {
newArticlesData = [...prevData, ...response.data];
} else {
newArticlesData = response.data;
}
if (response.meta.next_page != null) {
var rowCount = true;
} else {
var rowCount = Object.keys(newArticlesData).length;
}
if (this._mounted) {
this.setState({
isLoading: false,
//articlesDataSource: this.state.articlesDataSource.cloneWithRows(response.data),
articlesData: newArticlesData,
nextPage: response.meta.next_page,
fetchUrl: url,
rowCount: rowCount
});
}
}
})
.catch(error => {
this.setState({
errorFound: true,
errorMassage: error,
isLoading: false
});
});
Thanks for any help.
javascript react-native react-native-android
add a comment |
After compiling to android and downloading via Store I get the error:
"TypeError: Invalid attempt to spread non-iterable instance"
But using "react-native run-android" creates no error message therefor I can't find a good way to debug it.
fetch(url)
.then(response => response.json())
.then(response => {
if (this._mounted) {
// let dataSource = this.state.articlesDataSource.cloneWithRows(response.data || )
//var rowCount = dataSource.getRowCount();
var rowCount = Object.keys(response.data).length;
if (refresh == true) {
prevData = {};
} else {
prevData = this.state.articlesData;
}
if (propSearch == "" || propSearch == null) {
newArticlesData = [...prevData, ...response.data];
} else {
newArticlesData = response.data;
}
if (response.meta.next_page != null) {
var rowCount = true;
} else {
var rowCount = Object.keys(newArticlesData).length;
}
if (this._mounted) {
this.setState({
isLoading: false,
//articlesDataSource: this.state.articlesDataSource.cloneWithRows(response.data),
articlesData: newArticlesData,
nextPage: response.meta.next_page,
fetchUrl: url,
rowCount: rowCount
});
}
}
})
.catch(error => {
this.setState({
errorFound: true,
errorMassage: error,
isLoading: false
});
});
Thanks for any help.
javascript react-native react-native-android
There is a missing});
to close the.catch
– Shakespear
Dec 31 '18 at 21:13
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 yourprevData
is iterable, but is your response data? TrynewArticlesData=[...prevData, response.data]
?
– Drew Reese
Dec 31 '18 at 21:18
Although I see in an earlier check you setprevData={}
, which won't be spreadable into an array.
– Drew Reese
Dec 31 '18 at 21:22
@Shakespear just didn't paste it in. Added it.
– Freddy
Jan 1 at 17:26
add a comment |
After compiling to android and downloading via Store I get the error:
"TypeError: Invalid attempt to spread non-iterable instance"
But using "react-native run-android" creates no error message therefor I can't find a good way to debug it.
fetch(url)
.then(response => response.json())
.then(response => {
if (this._mounted) {
// let dataSource = this.state.articlesDataSource.cloneWithRows(response.data || )
//var rowCount = dataSource.getRowCount();
var rowCount = Object.keys(response.data).length;
if (refresh == true) {
prevData = {};
} else {
prevData = this.state.articlesData;
}
if (propSearch == "" || propSearch == null) {
newArticlesData = [...prevData, ...response.data];
} else {
newArticlesData = response.data;
}
if (response.meta.next_page != null) {
var rowCount = true;
} else {
var rowCount = Object.keys(newArticlesData).length;
}
if (this._mounted) {
this.setState({
isLoading: false,
//articlesDataSource: this.state.articlesDataSource.cloneWithRows(response.data),
articlesData: newArticlesData,
nextPage: response.meta.next_page,
fetchUrl: url,
rowCount: rowCount
});
}
}
})
.catch(error => {
this.setState({
errorFound: true,
errorMassage: error,
isLoading: false
});
});
Thanks for any help.
javascript react-native react-native-android
After compiling to android and downloading via Store I get the error:
"TypeError: Invalid attempt to spread non-iterable instance"
But using "react-native run-android" creates no error message therefor I can't find a good way to debug it.
fetch(url)
.then(response => response.json())
.then(response => {
if (this._mounted) {
// let dataSource = this.state.articlesDataSource.cloneWithRows(response.data || )
//var rowCount = dataSource.getRowCount();
var rowCount = Object.keys(response.data).length;
if (refresh == true) {
prevData = {};
} else {
prevData = this.state.articlesData;
}
if (propSearch == "" || propSearch == null) {
newArticlesData = [...prevData, ...response.data];
} else {
newArticlesData = response.data;
}
if (response.meta.next_page != null) {
var rowCount = true;
} else {
var rowCount = Object.keys(newArticlesData).length;
}
if (this._mounted) {
this.setState({
isLoading: false,
//articlesDataSource: this.state.articlesDataSource.cloneWithRows(response.data),
articlesData: newArticlesData,
nextPage: response.meta.next_page,
fetchUrl: url,
rowCount: rowCount
});
}
}
})
.catch(error => {
this.setState({
errorFound: true,
errorMassage: error,
isLoading: false
});
});
Thanks for any help.
javascript react-native react-native-android
javascript react-native react-native-android
edited Jan 1 at 16:42
Freddy
asked Dec 31 '18 at 21:02
FreddyFreddy
3511
3511
There is a missing});
to close the.catch
– Shakespear
Dec 31 '18 at 21:13
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 yourprevData
is iterable, but is your response data? TrynewArticlesData=[...prevData, response.data]
?
– Drew Reese
Dec 31 '18 at 21:18
Although I see in an earlier check you setprevData={}
, which won't be spreadable into an array.
– Drew Reese
Dec 31 '18 at 21:22
@Shakespear just didn't paste it in. Added it.
– Freddy
Jan 1 at 17:26
add a comment |
There is a missing});
to close the.catch
– Shakespear
Dec 31 '18 at 21:13
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 yourprevData
is iterable, but is your response data? TrynewArticlesData=[...prevData, response.data]
?
– Drew Reese
Dec 31 '18 at 21:18
Although I see in an earlier check you setprevData={}
, which won't be spreadable into an array.
– Drew Reese
Dec 31 '18 at 21:22
@Shakespear just didn't paste it in. Added it.
– Freddy
Jan 1 at 17:26
There is a missing
});
to close the .catch
– Shakespear
Dec 31 '18 at 21:13
There is a missing
});
to close the .catch
– Shakespear
Dec 31 '18 at 21:13
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]
?– Drew Reese
Dec 31 '18 at 21:18
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]
?– Drew Reese
Dec 31 '18 at 21:18
Although I see in an earlier check you set
prevData={}
, which won't be spreadable into an array.– Drew Reese
Dec 31 '18 at 21:22
Although I see in an earlier check you set
prevData={}
, which won't be spreadable into an array.– Drew Reese
Dec 31 '18 at 21:22
@Shakespear just didn't paste it in. Added it.
– Freddy
Jan 1 at 17:26
@Shakespear just didn't paste it in. Added it.
– Freddy
Jan 1 at 17:26
add a comment |
2 Answers
2
active
oldest
votes
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);
}
}
// error
trySpread({});
trySpread({foo: 'bar'});
trySpread(4);
// no error
trySpread();
trySpread(['foobar']);
trySpread('foobar');
Thats the API I am working with: link. I will try trySpread() on both objects. But newArticlesData=[...prevData, response.data] doesn't work, then I get an error later in my code that the object is "empty"
– Freddy
Jan 1 at 16:50
Well thats weird. I put "trySpread(prevData) trySpread(response.data)" before this.setState and get no console log at all.
– Freddy
Jan 1 at 16:57
Yeah, that example was just to illustrate how trying to spread non-iterable objects could fail.
– Drew Reese
Jan 1 at 18:31
add a comment |
I removed prevData and replaced it with this.state.articlesData.
I also change the logic so at the begining when articlesData is empty, it doesn't merge two objects, instead just uses the response.data.
if(propSearch=="" || propSearch==null && this.state.currentPage!=1 && refresh!=true){
newData=[...this.state.articlesData,...response.data]
}
else{
newData=response.data
}
this.state.currentPage!=1 is pretty much the same as oldData != empty
It workes now.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53991403%2ftypeerror-invalid-attempt-to-spread-non-iterable-instance%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
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);
}
}
// error
trySpread({});
trySpread({foo: 'bar'});
trySpread(4);
// no error
trySpread();
trySpread(['foobar']);
trySpread('foobar');
Thats the API I am working with: link. I will try trySpread() on both objects. But newArticlesData=[...prevData, response.data] doesn't work, then I get an error later in my code that the object is "empty"
– Freddy
Jan 1 at 16:50
Well thats weird. I put "trySpread(prevData) trySpread(response.data)" before this.setState and get no console log at all.
– Freddy
Jan 1 at 16:57
Yeah, that example was just to illustrate how trying to spread non-iterable objects could fail.
– Drew Reese
Jan 1 at 18:31
add a comment |
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);
}
}
// error
trySpread({});
trySpread({foo: 'bar'});
trySpread(4);
// no error
trySpread();
trySpread(['foobar']);
trySpread('foobar');
Thats the API I am working with: link. I will try trySpread() on both objects. But newArticlesData=[...prevData, response.data] doesn't work, then I get an error later in my code that the object is "empty"
– Freddy
Jan 1 at 16:50
Well thats weird. I put "trySpread(prevData) trySpread(response.data)" before this.setState and get no console log at all.
– Freddy
Jan 1 at 16:57
Yeah, that example was just to illustrate how trying to spread non-iterable objects could fail.
– Drew Reese
Jan 1 at 18:31
add a comment |
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);
}
}
// error
trySpread({});
trySpread({foo: 'bar'});
trySpread(4);
// no error
trySpread();
trySpread(['foobar']);
trySpread('foobar');
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);
}
}
// error
trySpread({});
trySpread({foo: 'bar'});
trySpread(4);
// no error
trySpread();
trySpread(['foobar']);
trySpread('foobar');
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');
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');
edited Dec 31 '18 at 21:38
answered Dec 31 '18 at 21:28
Drew ReeseDrew Reese
940211
940211
Thats the API I am working with: link. I will try trySpread() on both objects. But newArticlesData=[...prevData, response.data] doesn't work, then I get an error later in my code that the object is "empty"
– Freddy
Jan 1 at 16:50
Well thats weird. I put "trySpread(prevData) trySpread(response.data)" before this.setState and get no console log at all.
– Freddy
Jan 1 at 16:57
Yeah, that example was just to illustrate how trying to spread non-iterable objects could fail.
– Drew Reese
Jan 1 at 18:31
add a comment |
Thats the API I am working with: link. I will try trySpread() on both objects. But newArticlesData=[...prevData, response.data] doesn't work, then I get an error later in my code that the object is "empty"
– Freddy
Jan 1 at 16:50
Well thats weird. I put "trySpread(prevData) trySpread(response.data)" before this.setState and get no console log at all.
– Freddy
Jan 1 at 16:57
Yeah, that example was just to illustrate how trying to spread non-iterable objects could fail.
– Drew Reese
Jan 1 at 18:31
Thats the API I am working with: link. I will try trySpread() on both objects. But newArticlesData=[...prevData, response.data] doesn't work, then I get an error later in my code that the object is "empty"
– Freddy
Jan 1 at 16:50
Thats the API I am working with: link. I will try trySpread() on both objects. But newArticlesData=[...prevData, response.data] doesn't work, then I get an error later in my code that the object is "empty"
– Freddy
Jan 1 at 16:50
Well thats weird. I put "trySpread(prevData) trySpread(response.data)" before this.setState and get no console log at all.
– Freddy
Jan 1 at 16:57
Well thats weird. I put "trySpread(prevData) trySpread(response.data)" before this.setState and get no console log at all.
– Freddy
Jan 1 at 16:57
Yeah, that example was just to illustrate how trying to spread non-iterable objects could fail.
– Drew Reese
Jan 1 at 18:31
Yeah, that example was just to illustrate how trying to spread non-iterable objects could fail.
– Drew Reese
Jan 1 at 18:31
add a comment |
I removed prevData and replaced it with this.state.articlesData.
I also change the logic so at the begining when articlesData is empty, it doesn't merge two objects, instead just uses the response.data.
if(propSearch=="" || propSearch==null && this.state.currentPage!=1 && refresh!=true){
newData=[...this.state.articlesData,...response.data]
}
else{
newData=response.data
}
this.state.currentPage!=1 is pretty much the same as oldData != empty
It workes now.
add a comment |
I removed prevData and replaced it with this.state.articlesData.
I also change the logic so at the begining when articlesData is empty, it doesn't merge two objects, instead just uses the response.data.
if(propSearch=="" || propSearch==null && this.state.currentPage!=1 && refresh!=true){
newData=[...this.state.articlesData,...response.data]
}
else{
newData=response.data
}
this.state.currentPage!=1 is pretty much the same as oldData != empty
It workes now.
add a comment |
I removed prevData and replaced it with this.state.articlesData.
I also change the logic so at the begining when articlesData is empty, it doesn't merge two objects, instead just uses the response.data.
if(propSearch=="" || propSearch==null && this.state.currentPage!=1 && refresh!=true){
newData=[...this.state.articlesData,...response.data]
}
else{
newData=response.data
}
this.state.currentPage!=1 is pretty much the same as oldData != empty
It workes now.
I removed prevData and replaced it with this.state.articlesData.
I also change the logic so at the begining when articlesData is empty, it doesn't merge two objects, instead just uses the response.data.
if(propSearch=="" || propSearch==null && this.state.currentPage!=1 && refresh!=true){
newData=[...this.state.articlesData,...response.data]
}
else{
newData=response.data
}
this.state.currentPage!=1 is pretty much the same as oldData != empty
It workes now.
answered Jan 1 at 18:17
FreddyFreddy
3511
3511
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53991403%2ftypeerror-invalid-attempt-to-spread-non-iterable-instance%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
There is a missing
});
to close the.catch
– Shakespear
Dec 31 '18 at 21:13
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 yourprevData
is iterable, but is your response data? TrynewArticlesData=[...prevData, response.data]
?– Drew Reese
Dec 31 '18 at 21:18
Although I see in an earlier check you set
prevData={}
, which won't be spreadable into an array.– Drew Reese
Dec 31 '18 at 21:22
@Shakespear just didn't paste it in. Added it.
– Freddy
Jan 1 at 17:26