# react-native-better-hook-form

> React Native Better Hook Form is a custom hook that helps you handle easier the form submission.

Latest version **1.0.0** (published 2021-02-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-native-better-hook-form
pnpm add react-native-better-hook-form
yarn add react-native-better-hook-form
bun add react-native-better-hook-form
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2021-02-26 |
| First published | 2021-02-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Marius Atasiei |
| Maintainers | mariusatasiei |
| Keywords | react, react-native, hooks, react-hooks, react-native-hooks, form, react-form, react-hook-form, react-native-better-hook-form |

## Links

- npm: https://www.npmjs.com/package/react-native-better-hook-form
- npm.io page: https://npm.io/package/react-native-better-hook-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-02-26

## README

# React Native Better Hook Form

React Native Better Hook Form is a custom hook that helps you handle easier the form submission.

# How to install

```
npm install react-native-better-hook-form
```

OR

```
yarn add react-native-better-hook-form
```

# How to use

# 1. Import the hook:

```
import { useForm } from "react-native-better-hook-form"
```

# 2. Create a function:

```
function Form() {
    // ...
}
```
# 3. Destructure the hook:

```
function Form() {
    const { handleChange, checkErrors, errors, data } = useForm()
    // ...
}
```

The hook accept an object as parameter. The object can contains 2 properties:

* *default* - the default value of data

```
default: { 
    property: value
}
```

* *reqs* - requirements for every field

```
reqs: {
  inputName: {
    required: true || "Error message", // if required is true, the message will be [inputName] is required
    email: true || "Error message", // if email is true, the message will be [inputName] is not a valid email
    min:  number || {
      value: number,
      message: "Error message"
    }, // if min is of type number, the error message will be "[inputName] is too short"
    max:  number || {
      value: number,
      message: "Error message"
    } // if max is of type number, the error message will be "[inputName] is too long"
  }
}
```

EXAMPLE

```
useForm({
  default: {
    username: "guest"
  }, reqs:  {
    username:  {
      required: true,
      min: 8,
      max: {
        value: 32,
        message: "Maximum length is 32 characters"
      }
    }
  }
})
```

# 4. Create a form

```
function Form() {
    // ...
    return (
      <View>
        <TextInput name="username" onChange={(value) => handleChange("username", value)} />
        <Text>{errors.username}</Text>
        <Button title="submit" onPress={handleSubmit} />
      </View>
    )
}
```

# 5. Create handleSubmit function

```
const handleSubmit = () => {             
    const errorsExist = checkErrors()   
    if(errorsExist) return 
            
    console.log(data) 
    
    // manipulate data 
}
```

Check the React version [here](https://www.npmjs.com/package/react-better-hook-form)

Made by [Marius Atasiei](https://www.mariusatasiei.ro/)

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