TypeError: Invalid attempt to spread non-iterable instance












0















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.










share|improve this question

























  • 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











  • 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
















0















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.










share|improve this question

























  • 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











  • 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














0












0








0








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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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











  • @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













  • 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











  • @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












2 Answers
2






active

oldest

votes


















1














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');








share|improve this answer


























  • 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



















0














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.






share|improve this answer























    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    1














    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');








    share|improve this answer


























    • 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
















    1














    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');








    share|improve this answer


























    • 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














    1












    1








    1







    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');








    share|improve this answer















    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');






    share|improve this answer














    share|improve this answer



    share|improve this answer








    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



















    • 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













    0














    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.






    share|improve this answer




























      0














      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.






      share|improve this answer


























        0












        0








        0







        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.






        share|improve this answer













        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 1 at 18:17









        FreddyFreddy

        3511




        3511






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas