# @blockle/form

> Blockle Form

Latest version **2.1.2** (published 2022-06-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install @blockle/form
pnpm add @blockle/form
yarn add @blockle/form
bun add @blockle/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 | 2.1.2 |
| Published | 2022-06-14 |
| First published | 2019-03-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 22 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Niek Saarberg |
| Maintainers | saartje87 |

## Links

- npm: https://www.npmjs.com/package/@blockle/form
- Repository: git@github.com:Blockle/blockle-form
- npm.io page: https://npm.io/package/@blockle/form

## Recent versions

- 2.1.2 (latest) — 2022-06-14
- 0.0.1-alpha.11 (next) — 2019-11-25
- 2.1.1 — 2021-07-13
- 2.1.0 — 2021-07-13
- 2.0.1 — 2021-06-03
- 2.0.0 — 2021-05-18
- 1.0.1 — 2020-12-07
- 1.0.0 — 2020-02-03
- 1.0.0-alpha.0 — 2020-01-24
- 0.0.1-alpha.13 — 2019-11-26
- 0.0.1-alpha.12 — 2019-11-25
- 0.0.1-alpha.10 — 2019-10-29
- 0.0.1-alpha.9 — 2019-10-21
- 0.0.1-alpha.8 — 2019-10-21
- 0.0.1-alpha.7 — 2019-10-21
- … 6 more at https://npm.io/package/@blockle/form/versions

## README

# @blockle/form

## Install

```bash
yarn add @blockle/form
```

## Usage

```tsx
import React, { useState } from 'react';
import { Form, useField, useForm } from '@blockle/form';

interface UserForm {
  name: string;
}

const MyForm = () => {
  const form = useForm<UserForm>({
    async submit(data) {
      console.log('Form valid', data);
    },
  });

  // See form.values, form.erors

  return (
    <Form form={form}>
      <Input name="name" type="text" required />

      <button disabled={invalid || submitting}>Submit</button>
    </form>
  );
}

// Input.tsx
interface Props {
  name: string;
  value?: string;
  type: 'text' | 'password';
  required: boolean;
}

const Input: FC<Props> = ({ name, value, type, required }) => {
  const field = useField<string>({
    name,
    value,
    validate(value) {
      // Return string with "error code"
      if(required && !value.trim()) {
        return 'required';
      }

      return null;
    }
  });

  return (
    <input
      type={type}
      value={field.value}
      onChange={(event) => field.setValue(event.currentTarget.value)}
      onBlur={field.setTouched}
    />
  );
}
```

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