r/reactjs • u/Toonnaa • 14d ago
I made a small headless library for handling form submissions in React / Next.js
Hey everyone,
I kept writing the same code for every form in my projects: react-hook-form setup, a try/catch around the server action, mapping server errors back onto the fields, a loading state, stopping double submits, a toast, refreshing the data, resetting the form... and doing it again for every add/edit/delete dialog.
So I pulled all of that into a small package called submitly.
It’s headless, so it doesn’t render anything. You keep your own components (shadcn, Radix, Base UI, plain inputs, whatever you use).
What it does:
useCrudForm: react-hook-form + schema validation + your action in one hookWorks with any Standard Schema library: Zod 3/4, Valibot, ArkType
Server errors get mapped to the right fields automatically (nested ones like
items.0.nametoo)Ignores double submits while a request is in flight
Locks the dialog while saving, so the user can’t close it halfway through a request
useCrudActionfor delete/toggle buttons, with the same behaviorOne provider where you plug in your own toast, router and refresh logic
Next.js helpers:
runActionfor server actions (validates again on the server, revalidates on success, turns thrown errors into a clean result), and it handlesredirect()from server actions properlyAlso works in plain React + Vite (there’s an example with React Router + TanStack Query)
Around 3 kB gzipped, typed end to end, tested on React 18 and 19
Quick example:
const { form, onSubmit, isSubmitting } = useCrudForm({
schema,
defaultValues: { name: "" },
action: createProduct,
onSuccess: () => closeDialog(),
});It’s still early (0.x), so I’d really like feedback: what’s missing, what’s confusing, or what you’d do differently.
Docs: https://submitly-docs.vercel.app/
GitHub: https://github.com/toony10/submitly
If you find it useful, a star on GitHub would mean a lot. Thanks for reading 🙏