Search code examples
reactjsnode.jsreact-querytanstackreact-query

Why it shows error here? Bad argument type. Starting with v5, only the "Object" form is allowed when calling query related functions


Unexpected Application Error! Bad argument type. Starting with v5, only the "Object" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object

import { useQuery } from "@tanstack/react-query";

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>
);

};

export default AllUsers;


Solution

  • try to send parameter in an object format. Example:

        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>
        );