# @zhyd1997/use-form-hooks

> useForm hooks written with Typescript.

Latest version **0.4.1** (published 2022-01-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install @zhyd1997/use-form-hooks
pnpm add @zhyd1997/use-form-hooks
yarn add @zhyd1997/use-form-hooks
bun add @zhyd1997/use-form-hooks
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.1 |
| Published | 2022-01-25 |
| First published | 2021-10-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 31.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Yadong Zhang |
| Maintainers | lu1121 |
| Keywords | react, react-hooks, forms, form-validation |

## Links

- npm: https://www.npmjs.com/package/@zhyd1997/use-form-hooks
- Repository: https://github.com/zhyd1997/useForm
- Homepage: https://github.com/zhyd1997/useForm#readme
- Issues: https://github.com/zhyd1997/useForm/issues
- npm.io page: https://npm.io/package/@zhyd1997/use-form-hooks

## Dependencies (2)

- [@emotion/css](https://npm.io/package/@emotion/css.md) ^11.5.0
- [@emotion/react](https://npm.io/package/@emotion/react.md) ^11.5.0

## 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.4.1 (latest) — 2022-01-25
- 0.3.1 — 2021-12-04
- 0.2.1 — 2021-10-16
- 0.1.1 — 2021-10-11
- 0.1.0 — 2021-10-08
- 0.0.9 — 2021-10-08
- 0.0.8 — 2021-10-04
- 0.0.7 — 2021-10-02
- 0.0.6 — 2021-10-02
- 0.0.5 — 2021-10-02
- 0.0.4 — 2021-10-02
- 0.0.3 — 2021-10-01
- 0.0.2 — 2021-10-01
- 0.0.1 — 2021-10-01

## README

[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
![NPM](https://img.shields.io/npm/l/@zhyd1997/use-form-hooks)
![npm (scoped)](https://img.shields.io/npm/v/@zhyd1997/use-form-hooks)
[![codecov](https://codecov.io/gh/zhyd1997/useForm/branch/main/graph/badge.svg?token=8VLNN86IK0)](https://codecov.io/gh/zhyd1997/useForm)

![npm](https://img.shields.io/npm/dw/@zhyd1997/use-form-hooks?style=for-the-badge)
![npm](https://img.shields.io/npm/dm/@zhyd1997/use-form-hooks?style=for-the-badge)
![npm](https://img.shields.io/npm/dt/@zhyd1997/use-form-hooks?style=for-the-badge)

> Design useForm hooks and related components.

Demo: [CodeSandbox](https://codesandbox.io/s/blissful-browser-fop66?file=/src/components/BusinessForm.tsx)

# Features

- Support 4 types of input elements: `text`, `email`, `password` and `select`;
- Controlled Components;
- Validate form using [Constraint Validation API](https://developer.mozilla.org/en-US/docs/Web/API/Constraint_validation).

# Install

```bash
  # using npm
  npm install @zhyd1997/use-form-hooks
  # or using yarn
  yarn add @zhyd1997/use-form-hooks
```

# Usage

```jsx
import React from "react";
import { useForm, Form, Select, TextField } from "@zhyd1997/use-form-hooks";
import type { SelectProps, TextFieldProps } from "@zhyd1997/use-form-hooks";

function MyForm() {
  const { values, errors, onChange, handleSubmit } = useForm<InitialFormState>({
    username: "",
    email: "",
    role: "",
    password: ""
  });

  const onSubmit = () => {
    alert(JSON.stringify(values));
  };

  return (
    <div>
      <Form onSubmit={handleSubmit(onSubmit)}>
        <TextField {...formState.username} onChange={onChange} />
        <TextField {...formState.email} onChange={onChange} />
        <Select {...formState.select} onChange={onChange} />
        <TextField {...formState.password} onChange={onChange} />
        <button type="submit" className="cta-button">
          Submit
        </button>
      </Form>
    </div>
  );
}
```

# Development
When publishing a new release, you must at most do the 2 things below:

1. update `version` field in `package.json`.
2. update the version of package used in `examples`.

---
_Source: https://npm.io/package/@zhyd1997/use-form-hooks · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
