Skip to content

How to implement onSuccess, onError message after form submission like react-query? #4559

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

You must be logged in to vote

Update: created a tiny abstraction over useSubmit & useFetcher to get the react-query lifecycle hook behavior I needed in my app

useRemixSubmit & useRemixFetcher

These hook follows a similar API to the original useSubmit & useFetcher remix hook. Main difference is you can pass onSuccess, onError callbacks to the hook

// Example stackblitz sandbox: stackblitz.com/edit/node-s1xxwy?file=package.json,app%2Froutes%2Findex.tsx

const {submit, ...} = useRemixFetcher({
  onSuccess(){..}, 
  onError(){..}
})

const {submit, ...} = useRemixSubmit({
  onSuccess(){..}, 
  onError(){..}
})

Stackblitz example with source code: https://stackblitz.com/edit/node-s1xxwy?file=package.json,app%2Froutes%2Find…

Replies: 4 comments 7 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
6 replies
@andrelandgraf
Comment options

@tyteen4a03
Comment options

@andrelandgraf
Comment options

@dusty
Comment options

@tyteen4a03
Comment options

Comment options

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

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

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