-
Problem Statement:
How to access the response from // route/user/auth.tsx
export const action: ActionFunction = async ({ request }) => {
const form = await request.formData()
// code omitted for brevity
const users = JSON.stringify({
message: 'success',
user: { email },
})
return new Response(users, {
status: 200,
headers: {
location: '/admin',
},
})
} // route/admin.tsx
export default function index() {
const actionData = useActionData()
return (
<>
<Form method="post" replace action="/user/auth"
<input type="text" name="email" placeholder="email" />
<input type="password" name="password" placeholder="password" />
<button type="submit">submit</button>
</Form>
{actionData && <pre>{JSON.stringify(actionData, null, 2)}</pre>}
</>
)
} NOTE: I prefer to have an external route for @kentcdodds @sergiodxa Any advice? Also, Can some util be created to access the same? Like useRouteActionData( |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
From the Docs:
In your case, the action is not the route action. You can manually fetch with JS and receive the data there. Or you redirect in your action and provide the information via URL parameters. |
Beta Was this translation helpful? Give feedback.
From the Docs:
In your case, the action is not the route action. You can manually fetch with JS and receive the data there. Or you redirect in your action and provide the information via URL parameters.