# @deadcow-enterprises/react-form-hook

> A model-driven react form hook

Latest version **0.0.6** (published 2024-03-31) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @deadcow-enterprises/react-form-hook
pnpm add @deadcow-enterprises/react-form-hook
yarn add @deadcow-enterprises/react-form-hook
bun add @deadcow-enterprises/react-form-hook
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.0.6 |
| Published | 2024-03-31 |
| First published | 2023-10-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Deadcow.enterprises |
| Maintainers | deadcow-enterprises |
| Keywords | React, form, zod, typescript |

## Links

- npm: https://www.npmjs.com/package/@deadcow-enterprises/react-form-hook
- Repository: https://github.com/DeadCowDev/react-form-hook
- Issues: https://github.com/DeadCowDev/react-form-hook/issues
- npm.io page: https://npm.io/package/@deadcow-enterprises/react-form-hook

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.0.6 (latest) — 2024-03-31
- 0.0.5 — 2023-11-12
- 0.0.4 — 2023-10-16
- 0.0.3 — 2023-10-15
- 0.0.2 — 2023-10-15

## README

# React Form Hook

A model-driven, simple and typesafe approach to forms in React

## Features

- Simple to use
- Typesafe from start to end
- Lightweight
- Support for Zod

## Installation and usage

First install react-form-hook:

```bash
npm i @deadcow-enterprises/react-form-hook
```

then use it in your application

```javascript
import { useForm } from "@deadcow-enterprises/react-form-hook";
import { z } from "zod";

type LoginModel = {
  username: string,
  password: string,
};

function App() {
  const form =
    useForm <
    LoginModel >
    {
      username: {
        value: "",
        validator: z.string().min(1, "Username is required"),
      },
      password: {
        value: "",
        validator: z.string().min(1, "Password is required"),
      },
    };
  const login = (formValue: LoginModel) => {
    // do something with formValue here like send it to the server
    console.log(formValue);
  };
  return (
    <form onSubmit={form.handleSubmit(login)}>
      <label htmlFor="username">
        Username
        <input
          type="text"
          name="username"
          id="username"
          value={form.value.username}
          onChange={(ev) => {
            form.setValue("username", ev.target.value);
          }}
        />
        {form.errors.username?.map((err, i) => (
          <span className="error" key={i}>
            {err}
          </span>
        ))}
      </label>
      <label htmlFor="password">
        Password
        <input
          type="password"
          name="password"
          id="password"
          value={form.value.password}
          onChange={(ev) => {
            form.setValue("password", ev.target.value);
          }}
        />
        {form.errors.password?.map((err, i) => (
          <span className="error" key={i}>
            {err}
          </span>
        ))}
      </label>

      <button>Submit</button>
    </form>
  );
}
```

You can also check the example project repo [here](https://github.com/DeadCowDev/react-form-hook/tree/main/example)

## License

[MIT](https://choosealicense.com/licenses/mit/)

---
_Source: https://npm.io/package/@deadcow-enterprises/react-form-hook · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
