Issue
try {
console.log('11111')
const {
data: { tasks },
} = await axios.get('/api/v1/tasks')
console.log('22222 ' + await axios.get('/api/v1/tasks') )
console.log('33333 ' + tasks)
Issue is: tasks is undefined
Solution
The problem was in Backend.. the route associated with await axios.get('/api/v1/tasks') i.e get('/api/v1/tasks') had this code
``` const getAllTasks = async (req,res) => {
try{
const tasks = await Task.find({})
res.status(200).json(tasks)
}
catch(error){
res.status(500).send({msg: error})
}
}```
instead above. It should be
```const getAllTasks = async (req,res) => {
try{
const tasks = await Task.find({})
res.status(200).json({ tasks })
}
catch(error){
res.status(500).send({msg: error})
}
}```
The change is in res.status(200).json({ tasks })
Answered By - user19336910
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.