Sunday, 28 May 2017

waiting on data that is imported

I am working on a react app using Node.js. I had it working but to simplify my component I took out the fetch calls and put them into their own file (dataDown.js) and then imported them into the file. When I try to update state the data has downloaded yet. So how should I down get the data from external file making the fetch call. downdata is an object with two arrays in it

`fetch(urlRecent).then((response) => {

response
  .json()
  .then((data) => {
    dataDown.recent = data
  })
})
fetch(urlAllTime).then((response) => {

  response
    .json()
    .then((data) => {
      dataDown.alltime = data
    })
}).catch((err) => {
  console.log('Fetch Error :-S', err)
})

export default dataDown`

then i import it

import dataDown from '../../data/downData'



via Greg Duncan

No comments:

Post a Comment