TypeError in when storing data in array
<p>I use <a href="https://github.com/camsong/fetch-jsonp" rel="nofollow noreferrer">fetch-jsonp</a> to get some data from the darksky api, but when i fetch the data i get a TypeError when storing the data</p>

<pre><code>  constructor(props) {
        super(props);
        this.state = {
          daily: [],
          hourly: [],
          hourlySum: '',
          dailySum: '',
          loading: true,
          error: null
    };
  }

  componentDidMount() {
    if (navigator.geolocation){
      function success(position) {

        var latitude  = position.coords.latitude;
        var longitude = position.coords.longitude;
        var results = fetchJsonp(`https://api.darksky.net/forecast/key/`+latitude+`,`+longitude+`?units=auto`)
        .then(result =&gt; {
          this.setState({
            daily: result.daily.data,
            hourly: result.hourly.data,
            hourlySum: result.hourly,
            dailySum: result.daily,
            loading: false,
            error: null
          });
        })/*.catch(err =&gt; {
            // Something went wrong. Save the error in state and re-render.
            this.setState({
              loading: false,
              error: err
            });
          });*/
      };
      function error() {
        console.log( 'geolocation error' )
      };
      navigator.geolocation.getCurrentPosition(success.bind(this), error);
    }
  }
</code></pre>

<p>The error message is TypeError: Cannot read property 'data' of undefined referencing <code>daily: result.daily.data</code> but since i defined <code>daily</code> as an array i dont understand why i get a TypeError
<a href="https://darksky.net/dev/docs/forecast" rel="nofollow noreferrer">This</a> is the response format for reference</p>

<p>I did the same thing using Axios (which worked) but because of CORS i switched to JSONP.</p>

<p>My working Axios code looked like</p>

<pre><code>var _this = this;
    this.serverRequest = axios.get(`https://api.darksky.net/forecast/key/`+latitude+`,`+longitude+`?units=auto`)
    .then(result =&gt; {
      _this.setState({
        daily: result.data.daily.data,
        hourly: result.data.hourly.data,
        hourlySum: result.data.hourly,
        dailySum: result.data.daily,
        loading: false,
        error: null
      });
    })
</code></pre>

<p>Thanks in advance</p>