📚Cheatsheets

Cheatsheet collection for go, rust and javascript.

How to reset form after submit action in remix?

Here's what you need to do if you need to clear form after submitting in remix.

  • Setup the hook.
let transition = useTransition();
let isAdding = transition.state == "submitting";
let formRef = useRef<HTMLFormElement>(null);

useEffect(() => {
    if (!isAdding) {
        formRef.current?.reset();
    }
}, [isAdding]);
  • Don't forget to add the ref to form.
return (
        <Form ref={formRef}>
            ...
        </Form>
    )

See other cheatsheet's here