0

I'm using react for the first time alongside express, sequelize and node. The variable "json" below saves the parsed text. However I cannot access "json" outside of the function and iterate through its contents. This is the error I get:

Uncaught TypeError: Cannot read property 'tasks' of undefined(…)

Is there anyway of overcoming this? Thanks in advance.

getTasks() {
    var json;
    superagent.get('/api/tasks')
    .accept('json')
    .end(function(err, res) {
      if(err) throw err;
      json = JSON.parse(res.text);
    })
    json.tasks.map(task => (
        self.addTask(task.description)
    ));;
}
adeneo
  • 312,895
  • 29
  • 395
  • 388
feezy26
  • 3
  • 1

0 Answers0