Alternative to useActionData with Response for Easier Cookie Handling in React Router v7 (Framework Mode)? #13419
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello React Router community,
I'm working with React Router v7 in framework mode and using
useActionData
along with myaction
function.The basic example looks like this:
However, I need to set cookies upon successful login. To do this, I'm returning a
Response
object from myaction
:The issue I'm facing is that when I use
useActionData()
in my component:The
actionData
is a JSON string, and I have to manually parse it usingJSON.parse()
to access the data.The
BodyInit
type for the first argument ofResponse
includesstring
, which seems appropriate for my use case.My goal is to be able to set cookies in the server-side
action
and then easily access the returned data in the client-side component (usinguseActionData
) without having to manually parse a JSON string.Is there a more idiomatic or recommended way to achieve this in React Router v7 (framework mode)? I'm looking for a proper solution, not a workaround.
Thanks in advance for any suggestions!
Beta Was this translation helpful? Give feedback.
All reactions