# @flatom/forms-react

> Create forms for react

Latest version **0.7.16** (published 2022-11-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install @flatom/forms-react
pnpm add @flatom/forms-react
yarn add @flatom/forms-react
bun add @flatom/forms-react
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.7.16 |
| Published | 2022-11-10 |
| First published | 2022-08-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 94.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Evgeny |
| Maintainers | arswarog |
| Keywords | flatom, forms, final-forms |

## Links

- npm: https://www.npmjs.com/package/@flatom/forms-react
- npm.io page: https://npm.io/package/@flatom/forms-react

## Dependencies (1)

- [use-sync-external-store](https://npm.io/package/use-sync-external-store.md) ^1.2.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.7.16 (latest) — 2022-11-10
- 0.7.15 — 2022-09-07
- 0.7.14 — 2022-09-06
- 0.7.13 — 2022-09-05
- 0.7.12 — 2022-08-27
- 0.7.11 — 2022-08-27
- 0.7.10 — 2022-08-26
- 0.7.9 — 2022-08-26
- 0.7.8 — 2022-08-25

## README

# @flatom/forms-react

React bindings for Forms of [Flatom](https://github.com/arswarog/flatom).

[![npm](https://img.shields.io/npm/v/@flatom/forms-react?style=flat-square)](https://www.npmjs.com/package/@flatom/forms-react)
![npm type definitions](https://img.shields.io/npm/types/@flatom/forms-react?style=flat-square)
[![npm bundle size](https://img.shields.io/bundlephobia/minzip/@flatom/forms-react?style=flat-square)](https://bundlephobia.com/result?p=@flatom/forms-react)
![GitHub](https://img.shields.io/github/license/arswarog/flatom-react?style=flat-square)

## Install

`npm i @flatom/forms-react`

or

`yarn add @flatom/forms-react`

> `@flatom/forms` depends on `@flatom/core`, `@flatom/react` and `@flatom/forms`.

## Usage

### Step 1: Define you own validators and error messages
```ts
import { createSyncValidator } from '@flatom/forms';

const titleValidator = createSyncValidator('title', (prefix: string) => (value: string) => {
    if (value.startsWith(prefix)) {
        return null
    } else {
        return {
            prefixRequired: { prefix }
        }
    }
})                
                
const errorMessages: ValidationErrorMessages = {
    required: 'Required field',
    children: 'Please fill all fields',
    min: 'Value have to more then {min}',
    max: 'Value have to less then {max}',
    prefixRequired: 'Require prefix: {prefix}',
};
```

### Step 2. Define form schema

```ts
import { declareFormSchema, validators } from '@flatom/forms';

const formSchema = declareFormSchema({
    id: 'my-form',
    nullable: true,
    controls: {
        title: {
            defaultValue: '',
            validators: [validators.required(), titleValidator('prefix ')],
        },
        value: {
            defaultValue: 0,
            validators: [validators.required(),validators.min(1), validators.max(100)],
        },
    },
});
```

### Step 3: Create field

// todo

### Step 4: Create form

```tsx
const MyForm = ()=> {
    const form = useForm(addTransactionFormSchema, formValidators, errorMessages);

    return (
        <FlatomForm
            form={props.form}
            onSubmit={onSubmit}
            onSubmitInvalid={onSubmitInvalid}
        >
        </FlatomForm>
    )
}
```

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