Handling post-server actions with useActionState
Answered
Braque Francais posted this in #help-forum
Braque FrancaisOP
The most basic example of this would be showing a toast after a server action completes. This is what I'm currently trying:
I feel like this should work, yet action does not await. Is there a way to do something like this? It makes me think I'm missing something fundamental about how this should work. Thanks!
const [lastResult, action, isPending] = useActionState(myServerAction, undefined);
const doSomething = async (formData: FormData) => {
const result = await action(formData); // action doesn't return a promise, so await is doing nothing
// Do something, like show a toast
return result;
}
return <form action={doSomething}>........
I feel like this should work, yet action does not await. Is there a way to do something like this? It makes me think I'm missing something fundamental about how this should work. Thanks!