forge42dev / remix-hook-form

Open source wrapper for react-hook-form aimed at Remix.run
MIT License
354 stars 29 forks source link

How to handle submit success? #39

Closed lucgagan closed 1 year ago

lucgagan commented 1 year ago
  const {
    data,
    errors,
    receivedValues: defaultValues,
  } = await getValidatedFormData<FormData>(request, resolver);

  if (errors) {
    return json({ defaultValues, errors });
  }

  // router.push(`/article/${data.id}/outline`);

  return json(data);
};

export default () => {
  const form = useRemixForm<FormData>({
    mode: 'onSubmit',
    resolver,
  });

  // toast({
  //   title: 'Article Project Created',
  // });

My use case is that I want to trigger toast after successful action.

AlemTuzlak commented 1 year ago

@lucgagan if you want to redirect to somewhere with a toast notification you can use: https://github.com/Code-Forge-Net/remix-toast If you want to return the data to frontend and show a notification on the same screen you can just use

const data = useActionData();
useEffect(() => {
  if(data){
    toast(...)
  }
},[data])

but yeah this issue is not related to the library itself it's just a matter of how you implement it so I will close it, but the above approaches will work

lucgagan commented 1 year ago

Thank you