-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useLoaderData
returns undefined
when used in root.tsx
#9717
Comments
In Remix, the actual behavior is the correct behavior. Typically things like toast messages would be set via Since you're creating a SPA, you may want to use something like export async function clientAction() {
// call the toast function directly
toast('hello remix');
return null;
} https://stackblitz.com/edit/remix-run-remix-bt6c8m?file=app%2Froot.tsx,app%2Froutes%2F_index.tsx |
@kiliman is correct here - |
Thanks for the suggestion @kiliman! @brophdawg11 in that case I feel the docs are a bit unclear, since they mention that:
That made me think I could |
PRs are always welcome to clarify the docs! Would you like to push a PR with a proposed clearer wording? |
The current documentation for the `useActionData` hook might unintentionally imply that it can be used to access data from any route action. However, the hook is limited to accessing data associated with the current route action where it's called. This PR clarifies this limitation in the documentation to prevent confusion. See remix-run#9717 for more information.
@brophdawg11 sure thing! #9744 |
Reproduction
root.tsx
and_index.tsx
renderundefined
as the output of theuseActionData
hook (see rendered messages on the page.Click to submit
button to call theclientAction
form the_index.tsx
route.useActionData
returns{toast: "foo"}
in the_index.tsx
route, but returnsundefined
inroot.tsx
(see rendered messages on the page.System Info
Used Package Manager
npm
Expected Behavior
I was expecting to access the (the serialized data from the most recent route action)[https://remix.run/docs/en/main/hooks/use-action-data] in
root.tsx
to implement anToasts
component.The
clientAction
on_index.tsx
would do stuff and return{toast: "message"}
as part of the response (other routes do this as well) and inroot.tsx
I wanted to render the toasts (when present).This is a Remix SPA project (that's why we use a
clientAction
instead ofaction
).Actual Behavior
useActionData
returns theclientAction
response only in the route where the client action is defined.The text was updated successfully, but these errors were encountered: