-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Fix useActionData so it only returns the contextual route action data #11023
Conversation
🦋 Changeset detectedLatest commit: c5670d0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
🤖 Hello there, We just published version Thanks! |
🤖 Hello there, We just published version Thanks! |
Hey @brophdawg11, We just bumped our remix version to 2.3.0 which includes this PR. The fix you did in this PR was unfortunately a feature for us.
Do you know how to re-create a hook allowing us to "listen" to any route action? |
Though this relies on import { useContext } from 'react';
import { UNSAFE_DataRouterStateContext } from 'react-router';
function useAnyActionData() {
const state = useContext(UNSAFE_DataRouterStateContext);
return Object.values(state?.actionData || {})[0];
} I tested it based on the reproduction from #11022 (comment) https://stackblitz.com/edit/remix-run-remix-wab4bq?file=app%2Froutes%2Fparent.tsx |
Darn! Looks like we were relying on this "bug", and fixing it broke nasa-gcn/gcn.nasa.gov#1699. |
Thanks @hi-ogawa, it's nice to be able to choose between the two implementations. |
@lildesert I would recommend using a flashed session value for toast messages like that: https://remix.run/docs/en/main/utils/sessions#sessionflashkey-value |
Neat, thank you! |
Closes #11022
This has been a bug since the move from TransitionManager (https://github.com/remix-run/remix/blob/%40remix-run/vercel%401.7.6/packages/remix-react/components.tsx#L1421).
useActionData
should behave the same asuseLoaderData
in this regard.