clear input after server action?
Unanswered
Southern African anchovy posted this in #help-forum
Southern African anchovyOP
If I use a server action to submit form data, how can I clear the input on the client after submitting the data?
3 Replies
Southern African anchovyOP
I'm using revalidatePath to refetch data but my text input still has the value I submitted
Thrianta
did you found how to do it? im also looking for it
@Thrianta did you found how to do it? im also looking for it
"use client";
import { action } from "@/lib/action";
import { useRef } from "react";
export function Form() {
const formRef = useRef<HTMLFormElement>(null);
return (
<form
ref={formRef}
action={async (formData) => {
await action(formData);
formRef.current?.reset();
}}
>
<input type="text" name="name" />
<button>submit</button>
</form>
);
}