小编Bal*_*ius的帖子

react-query useQuery typescript 没有重载与此调用匹配

我正在尝试使用打字稿进行反应查询教程,但是在获取数据时发生了错误。

代码:

type heroType = {
  id: number;
  name: string;
  alterEgo: string;
};

function QueryDataFetch() {
  const fetchdata = ()=>{ return axios.get("http://localhost:8000/superheroes")}
  const { isLoading, data ,error} = useQuery<heroType[]>(["heros"],fetchdata);
Run Code Online (Sandbox Code Playgroud)

此错误红色 unline 显示在fetchdata

数据:

[
{
"id": 1,
"name": "Batman",
"alterEgo": "Bruce Wayne"
},
{
"id": 2,
"name": "Superman",
"alterEgo": "Clark Kent"
},
{
"id": 3,
"name": "Wonder Woman",
"alterEgo": "Princess Diana"
}
]
Run Code Online (Sandbox Code Playgroud)

错误:

TS2769: No overload matches this call.
  The last overload gave the following error.
    Argument of …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs react-query

1
推荐指数
1
解决办法
3390
查看次数

标签 统计

react-query ×1

reactjs ×1

typescript ×1