An open API service indexing awesome lists of open source software.

https://github.com/ilxanlar/react-hooks-form

React Forms the Hooks Way
https://github.com/ilxanlar/react-hooks-form

form hooks react react-hooks-form

Last synced: 3 months ago
JSON representation

React Forms the Hooks Way

Awesome Lists containing this project

README

        

# React Hooks Form

React Hooks Form offers an easy way to manage your forms in React.
It's built using the famous React Hooks!

### Documentation

You can find the complete documentation [here](https://ilxanlar.github.io/react-hooks-form).

### Usage

Install via NPM or Yarn:

```
npm install react-hooks-form --save
yarn add react-hooks-form
```

The following code snippet is a basic example of using React Hooks Form.

```jsx harmony
import React from 'react'
import { Form, FormField } from 'react-hooks-form'

async function handleSubmit(values) {
try {
await _myApiRequest(values)
} catch (error) {
alert(error.message)
}
}

function SignUpForm() {
return (




Sign Up

)
}
```

### Hooks

```js
// Hook to field value
const amount = useFormFieldValue('amount')

// Hook to field error, focus status and ...
const {
active,
error,
invalid,
visited
} = useFormFieldMeta('amount')

// Hook to get form all values
const values = useFormValues()

// Hook to form submission status, errors and ...
const {
submitting,
submitFailed,
submitSucceeded,
error
} = useFormMeta()

// Hook to access form API
const formApi = useForm() // There are plenty of methods
```