Skip to content

How to return custom data/error on action #7

Answered by AlemTuzlak
ronkristoff asked this question in Q&A
Discussion options

You must be logged in to vote

I think your main issue here @ronkristoff is that your

export const action = async ({ request }: ActionArgs) => {
  const {
    errors,
    data,
    receivedValues: defaultValues,
  } = await getValidatedFormData(request, resolver);
  if (errors) {
     return json({ errors, defaultValues });
  }
  //return some data that comes from custom validation
  return json({ customErrors: "test" });

is returning either errors and defaultValues or customErrors, if you try doing it like this:

export const action = async ({ request }: ActionArgs) => {
  const {
    errors,
    data,
    receivedValues: defaultValues,
  } = await getValidatedFormData(request, resolver);
  if (errors) {
     return json(

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by AlemTuzlak
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants