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

https://github.com/hjyup/use-react-hook-form-persist

Lightweight persistence for react-hook-form with nested field support.
https://github.com/hjyup/use-react-hook-form-persist

library npm-package persistence react react-hook-form typescript

Last synced: 2 months ago
JSON representation

Lightweight persistence for react-hook-form with nested field support.

Awesome Lists containing this project

README

          

# use-react-hook-form-persist

A lightweight hook for persisting form state in `react-hook-form`, with support for nested fields, custom storage, and full control.

## 🚀 Usage

A small example how you can use this hook:

```javascript
import { useForm } from "react-hook-form";
import { useFormPersist } from "use-react-hook-form-persist";

type FormValues = {
name: string,
email: string,
password: string
};

export function ProfileForm() {
const form =
useForm <
FormValues >
{
defaultValues: {
name: "John Doe",
email: "john.doe@example.com",
password: ""
}
};

const persistedForm = useFormPersist(form, {
key: "form-data"
});

const { register, handleSubmit } = persistedForm;

return (
console.log(values))}>



Save

);
}
```

## 📦 Installation

Using your preferred package manager:

```bash
# with pnpm
pnpm add use-react-hook-form-persist

# or with npm
npm install use-react-hook-form-persist

# or with yarn
yarn add use-react-hook-form-persist
```

## ✨ Features

- Full control over storage (localStorage, sessionStorage, or custom) and serialisation parser.
- Works seamlessly with deeply nested form values, arrays, and objects.
- Include or exclude specific fields and paths with fine-grained control.
- Handle schema changes gracefully with version numbers and optional mismatch callbacks.
- Powered by TypeScript and react-hook-form’s path types for strong guarantees.

## License

[MIT](https://choosealicense.com/licenses/mit/)