Using useNavigate within client-only action/query
The docs says:
If you are inside of a cache or action function you will instead [of useNavigate] want to use redirect or reload.Does that include query/actions that only run on the client (don't use
"use server"
)?4 Replies
Yes, cache and action detect the Response object and act on it on both client and server
So I cannot use
useNavigate
with query
or action
at all?
If yes, why?Correct, since useNavigate needs to be called inside components but queries/actions are usually defined outside.
Technically if you had a client-only query/action you could pass in the navigate function from useNavigate as an argument but I don’t think there’s much point doing that
Also worth noting - a query not having ‘use server’ doesn’t necessarily mean it won’t be run on the server, since it could still get called on the server during ssr
Thanks