How to trigger a Server Action from an `onBlur` event?
Unanswered
Cassin's Sparrow posted this in #help-forum
Cassin's SparrowOP
How to trigger a Server Action from an
onBlur event?12 Replies
Cassin's SparrowOP
I'm assuming this can be done with
useTransition, can I still use useOptimistic then?That can be done by
useTransition and useOptimistic also works without a form, but I usually recommend using a route handler instead.Cassin's SparrowOP
Awesome! Why would you recommend using a route handler instead?
Cassin's SparrowOP
I've tried and it works! Just curious @fuma, why would you recommend a route handler instead?
Because developers usually use
fetch with client-side revalidations in production applications. In these cases route handler will be a better choiceCassin's SparrowOP
useOptimistic doesn't work with route handlers, right?useOptimistic is just a hook provided by React, it can be used with anythingCassin's SparrowOP
That makes sense, thanks for your help!
Cassin's SparrowOP
One more question @fuma , can you get the returned value from the Server Action with
useTransition?Although server actions are not used for data fetching, but you can receive the retuned value since
startTransition accepts an async functionCassin's SparrowOP
Thanks! 🔥
btw if your problem has been solved, you can mark my answer as the solution 
