npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-form-submitter

v1.0.1

Published

Submitter callback hook to use with React Hook Form

Readme

react-form-submitter

Submitter callback hook to use with React Hook Form

Expands the submission logic of React Hook Form to include:

  • Submit either to an endpoint (with fetch) or to a server action, or any function
  • Transform data before submission
  • Submit only changed data - no need to send values to be ignored!
  • Callbacks for onSuccess, onFailure, onError
  • Possible to ask confirmation before submission
  • Callback for mutate, in case the form's default values are dynamically fetched using something like TanStack Query

Example

import { useForm } from "react-hook-form";
import { useSubmitter } from "react-form-submitter";

interface FormData {
	name: string;
	age: number;
}

function MyForm({ defaultValues }: { defaultValues: FormData }) {
	const { register, handleSubmit } = useForm<FormData>({
		defaultValues,
	});
	const { isFailed, submitter } = useSubmitter<FormData>(myServerAction, {
		defaultValues,
		onSuccess() {
			console.log("Success!");
		},
	});

	return (
		<form onSubmit={handleSubmit(submitter)}>
			{isFailed && <p>Submission Failed</p>}
			<input {...register("name")} />
			<input {...register("age")} />
			<input type="submit" />
		</form>
	);
}

Options:

destination: The first argument. Can be either a string - in which case it's used as a fetch endpoint - or a function.

If a string, submit sends the data as a form data in a fetch request, with the destination as the endpoint.

If a function, submit sends the data to the function.

defaultValues: If provided, values matching those are not submitted.

method: The fetch method. Defaults to "POST".

onSuccess: Callback, to be called when the submission is successfull. Called with the submitted data and the fetch response.

onFailure: Callback, to be called when the submission fails, but does not throw. Called with the submitted data and the fetch response.

onError: Callback, to be called when the submission throws. Called with the error.

transform: Function to transform the form's data before submission and before comparison to the default values.

fetchOptions: Options to provide to the fetch call.

confirmation: If provided, asks for confirmation using this string as a message before submitting.

mutate: Callback, to be called with the transformed data after a successful submission.