Skip to content

Fetch data qith useQuery Next.js cookie #2889

Answered by TkDodo
marcianosr asked this question in Q&A
Discussion options

You must be logged in to vote

the from prefetching have to match the keys exactly on useQuery. So if you do:

await queryClient.prefetchQuery(["users", cookie], async () => {
    return getLiftsFromUsers(cookie);
});

on the server, you also need to use ["users", cookie] on the client.

const { data, error } = useQuery("users", getLiftsFromUsers); // How does this work? 

so here, you would need to use the same key, and also pass the cookie to getLiftsFromUsers, like:

const { data, error } = useQuery(["users", cookie], () => {
    return getLiftsFromUsers(cookie);
});

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@marcianosr
Comment options

@TkDodo
Comment options

@marcianosr
Comment options

Answer selected by marcianosr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants