Skip to content

Use multiple actions on same route #1052

Closed Answered by sergiodxa
JakovGlavac asked this question in Q&A
Discussion options

You must be logged in to vote

An action needs to return one of two things.

  1. A redirect to another URL
  2. Data (or a response with data) to be accessed through useActionData

The redirect works all the time, the data to be accessed through useActionData will only work if the action is on a route with a component.

So in your case because you moved the action to another file you need to do a redirect, in case of an error you should store any error message in the session with session.flash, redirect to the previous URL (you can use redirectBack from Remix Utils) and then in the loader read the errors from the session with session.get and return them as part of the loader data.

If you want to keep using useActionData you need…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@JakovGlavac
Comment options

Answer selected by JakovGlavac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants