Minimal form example

This is the most basic usage example you can use. If you need a plain form, just copy and paste the code.

Object names is not mandatory, however it helps prevent errors so it's always included in the examples. More info about names and other return types can be found in the Documentation section.

import React from "react";
import { useBrowserForm } from "react-browser-form";

const defaultValues = {
  email: "",
};
type Form = typeof defaultValues;

export function ExampleMinimalForm() {
  const [data, setData] = React.useState<Form>();

  const { formProps, names } = useBrowserForm<Form>({
    name: "example-minimal-form",
    defaultValues,
    onSubmit: setData,
  });

  return (
    <form {...formProps}>
      <input type="text" placeholder="E-mail address" name={names.email} />
      <button type="submit">Subscribe</button>
    </form>
  );
}
Form meta
Submitted?
No
Has errors?
No
Is dirty?
No
Change reason
Form state