reactjs - React Native: undefined is not an object (evaluating '_this.setState') -
i'm @ bit of loss why i'm getting error message in simulator code below. line # indicated in comment.
this.setstate seems in correct object format.
fetchdata: function() { fetch(apiurl) .then((response) => response.json()) .then((responsedata) => { this.collectresponses(responsedata); }) .then((responseobject) => { this.sortpredictions(responseobject); }) .then((predictionsobj) => { this.setstate({ // error here! castroinktlm: predictionsobj['5728'], churchinktlm: predictionsobj['5726'], churchinj: predictionsobj['4006'], churchinn: predictionsobj['4448'], montgout: predictionsobj['6994'], church37in: predictionsobj['7073'], church37out: predictionsobj['5667'], castro37out: predictionsobj['3325'], castro33in: predictionsobj['3255'], fetchtime: predictionsobj['fetchtime'] }); }) .done(); },
i have not done react-native yet, believe error seeing, due this not within function scope (the 1 receives predictionsobj) parameter
fetchdata: function() { var self = this; fetch(apiurl) .then((response) => response.json()) .then((responsedata) => { this.collectresponses(responsedata); }) .then((responseobject) => { this.sortpredictions(responseobject); }) .then((predictionsobj) => { self.setstate({ castroinktlm: predictionsobj['5728'], churchinktlm: predictionsobj['5726'], churchinj: predictionsobj['4006'], churchinn: predictionsobj['4448'], montgout: predictionsobj['6994'], church37in: predictionsobj['7073'], church37out: predictionsobj['5667'], castro37out: predictionsobj['3325'], castro33in: predictionsobj['3255'], fetchtime: predictionsobj['fetchtime'] }); }) .done(); },
Comments
Post a Comment