Is it possible to retrieve the data acquired in the parent action without having to refetch them?
For example:
routes/parent.tsx
routes/parent.$id.tsx
In the parent.tsx
, in action route, I get some data:
export const action: ActionFunction = async ({ request }) => {
const data = something
return data;
}
How to get these same data in the child route parent.$id.tsx
without having to refetch them in the loader route ?
2
Answers
I can't get it to work,
useOutletContext
returnundefined
in child route (parent.$id.tsx
).Here is a sample code (based on https://docs.w3cub.com/react_router/hooks/use-outlet-context)
parent.tsx
parent.$id.tsx
What is wrong in this code ?
The useOutletContext hook is what you are looking for.
Details are in the docs: https://remix.run/docs/en/main/hooks/use-outlet-context