React Native Error: Possible Unhandled Promise Rejection - Cannot read property data
<p>I'm having a strange problem that I can't quite pinpoint with my React Native app. I'm using Lodash to cycle through a API response to set the state of an array of locations using the returned response after clearing the array. When I display just the value / key of the response within the loop, it works fine, but when I try using setState, I get a possible unhanded promise error. </p>

<p>Here's the code for the loop and setting state:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>    updateMarkers(payload) {
        this.setState({
            markers: []
        })
        let id = 0
        _.forOwn(payload, function(value, key) {
            this.setState({
                markers: [
                    ...this.state.markers,
                    {
                        coordinate: key.coordinates,
                        key: id++
                    }
                ]
            })
        })
        console.log(this.state.markers)
    }</code></pre>
</div>
</div>
</p>

<p>Here's the response I'm receiving:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>Possible Unhandled Promise Rejection (id: 0):
Cannot read property 'data' of undefined
TypeError: Cannot read property 'data' of undefined
    at http://localhost:8081/index.ios.bundle?platform=ios&amp;dev=true&amp;minify=false:113197:55
    at tryCallOne (http://localhost:8081/index.ios.bundle?platform=ios&amp;dev=true&amp;minify=false:25822:8)
    at http://localhost:8081/index.ios.bundle?platform=ios&amp;dev=true&amp;minify=false:25908:9
    at JSTimersExecution.callbacks.(anonymous function) (http://localhost:8081/index.ios.bundle?platform=ios&amp;dev=true&amp;minify=false:8801:13)
    at Object.callTimer (http://localhost:8081/index.ios.bundle?platform=ios&amp;dev=true&amp;minify=false:8581:1)
    at Object.callImmediatesPass (http://localhost:8081/index.ios.bundle?platform=ios&amp;dev=true&amp;minify=false:8680:19)
    at Object.callImmediates (http://localhost:8081/index.ios.bundle?platform=ios&amp;dev=true&amp;minify=false:8695:25)
    at http://localhost:8081/index.ios.bundle?platform=ios&amp;dev=true&amp;minify=false:7405:43
    at guard (http://localhost:8081/index.ios.bundle?platform=ios&amp;dev=true&amp;minify=false:7283:1)
    at MessageQueue.__callImmediates (http://localhost:8081/index.ios.bundle?platform=ios&amp;dev=true&amp;minify=false:7405:1)</code></pre>
</div>
</div>
</p>

<p>This is what the returned object looks like when I console log the value and key (without setting state). It cycles through each object correctly.</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>Object {coordinates: Object, description: "Machine F", distance: 1.220632249131323, inventory: Array[16], pid: "-KP6ulcT9qeDb1oFFrVA"}
coordinates:Object
description:"Machine F"
distance:1.220632249131323
inventory:Array[16]
pid:"-KP6ulcT9qeDb1oFFrVA"
__proto__:Object</code></pre>
</div>
</div>
</p>

<p>Any help would be greatly appreciated!</p>