NodeJS 为什么这里显示错误?错误的参数类型,从v5开始,调用查询相关函数时只允许“Object”形式

vmpqdwk3  于 12个月前  发布在  Node.js
关注(0)|答案(2)|浏览(138)

应用程序错误!错误的参数类型。从v5开始,调用查询相关函数时只允许“Object”形式。请使用错误堆栈查找罪魁祸首调用。更多信息请访问:https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object
从“@tanstack/react-query”导入{ useQuery };
const AllUsers =()=> {

const {data: users = [], refetch} = useQuery(['users'], async() => {
    const res = await fetch('http://localhost:5000/users')
    return res.json();
   })

return (
    <div>
        {users.length}
    </div>
);

字符串
};
导出默认值AllUsers;

qvtsj1bj

qvtsj1bj1#

尝试以对象格式发送参数。示例:

const {data: users = [], refetch} = useQuery({queryKey:['users'], queryFn: async() => {
        const res = await fetch('http://localhost:5000/users')
        return res.json();
       })
    
    
    return (
        <div>
            {users.length}  
        </div>
    );

字符串

cgvd09ve

cgvd09ve2#

  • //我有这个问题;这个问题的解决方案;*
const { data: users = [], refetch } = useQuery({
    queryKey: ["users"],
    queryFn: async () => {
      const res = await fetch("http://localhost:5000/users");
      return res.json();
    },   });

  return <div>{users.length} </div>;

字符串

相关问题