# use-flat-form

> [![NPM](https://img.shields.io/npm/v/use-flat-form.svg)](https://www.npmjs.com/package/use-flat-form) ![NPM License](https://img.shields.io/npm/l/use-flat-form) ![minified size](https://img.shields.io/bundlephobia/min/use-flat-form)

Latest version **1.0.0** (published 2021-05-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install use-flat-form
pnpm add use-flat-form
yarn add use-flat-form
bun add use-flat-form
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2021-05-27 |
| First published | 2021-05-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 0 |
| Unpacked size | 11.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Akshay Gaonkar |
| Maintainers | 9paradox |
| Keywords | flat-form, form, input, form input, multiple input, input hook, useState, react-hook, react |

## Links

- npm: https://www.npmjs.com/package/use-flat-form
- Repository: https://github.com/9paradox/use-flat-form
- Homepage: https://github.com/9paradox/use-flat-form#readme
- Issues: https://github.com/9paradox/use-flat-form/issues
- npm.io page: https://npm.io/package/use-flat-form

## 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

- 1.0.0 (latest) — 2021-05-27
- 0.1.0 — 2021-05-27

## README

# useFlatForm

[![NPM](https://img.shields.io/npm/v/use-flat-form.svg)](https://www.npmjs.com/package/use-flat-form)  ![NPM License](https://img.shields.io/npm/l/use-flat-form) ![minified size](https://img.shields.io/bundlephobia/min/use-flat-form)

A simple react form hook for multiple inputs. 

No need to create multiple useState hooks to manage your react form.

## Install

```bash
npm i use-flat-form
```

## Usage

```tsx
import * as React from 'react'

import useFlatForm from 'useFlatForm'

//your initial state
const initState = {
  name: '',
  age: 0,
};

//initialize useFlatForm which returns:-
//  'state' : with object structure of the initial state
//  'setInputState' : function to set input filed value, filed name should match state property
//  'setFormState' : function to set value for entire form state
const [state, setInputState, setFormState] = useFlatForm(initState);

//to use the state
<p>{state.name}</p>
<p>{state.age}</p>

//to set value to an input field (supports type hinting)
<input value={state.name} onChange={e => setInputState('name', e.target.value)} />
<input value={state.age} onChange={e => setInputState('age', e.target.value)} />

//to set value for the entire form
setFormState({ name: 'some name', age: 20 });
```

## Examples

1. [Simple useFlatForm react app example](https://github.com/9paradox/use-flat-form/blob/main/example/index.tsx) 

## License

[MIT](https://github.com/9paradox/use-flat-form/blob/main/LICENSE)

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