-
I'm trying to use react-query inside the loader function using createBrowserRouter. So, what I did was this: const router = createBrowserRouter([
{
path: "/",
element: <Home />,
loader:
async ({ _, params }) =>
() => {
const { data, isLoading } = useFetchRoute(params);
if (!isLoading && !data) throw new Response("Not Found", { status: 404 });
return data;
},
}
]); Is this considered bad practice? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 4 replies
-
It is not possible to use hooks inside loaders. This article could help you integrating with React Query. |
Beta Was this translation helpful? Give feedback.
-
I have a similar requirement. I want to get the auth state from redux in the loader to make some decision. As of now I don't find any way to inject that data into the loader. Any help would be appreciated. |
Beta Was this translation helpful? Give feedback.
-
I have a similar requirement. Trying to execute some Redux logic inside the loader. |
Beta Was this translation helpful? Give feedback.
-
@ralph993 hello !! Quick question, how did you type Thanks :) |
Beta Was this translation helpful? Give feedback.
It is not possible to use hooks inside loaders. This article could help you integrating with React Query.