首页 > 解决方案 > useQuery : 没有获取数据

问题描述

当我记录未定义的数据时,但是当我登录时,我会看到数据。知道为什么吗?

const {data}= useQuery('get-todos',()=>{axios.get('http://localhost:8080/todos').then(res => res.data)})

标签: javascriptreactjsreact-query

解决方案


您的查询函数需要从 axios 返回承诺:

const {data}= useQuery('get-todos',() => {
    return axios.get('http://localhost:8080/todos').then(res => res.data)
})

推荐阅读