# mui-rhf

> Form generator based on Material UI and React Hook Form

Latest version **1.0.1** (published 2021-06-15) · ISC license · 0 weekly downloads

## Install

```sh
npm install mui-rhf
pnpm add mui-rhf
yarn add mui-rhf
bun add mui-rhf
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2021-06-15 |
| First published | 2021-01-31 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 37.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | clement-faure |
| Maintainers | clement-faure |
| Keywords | react, typescript, npm, material-ui, react-hook-form |

## Links

- npm: https://www.npmjs.com/package/mui-rhf
- Repository: https://github.com/clement-faure/mui-rhf
- Homepage: https://github.com/clement-faure/mui-rhf#readme
- Issues: https://github.com/clement-faure/mui-rhf/issues
- npm.io page: https://npm.io/package/mui-rhf

## 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.1 (latest) — 2021-06-15
- 0.0.11 — 2021-04-29
- 0.0.10 — 2021-04-11
- 0.0.9 — 2021-04-11
- 0.0.6 — 2021-03-28
- 0.0.5 — 2021-02-25
- 0.0.4 — 2021-02-25
- 0.0.3 — 2021-02-01
- 0.0.2 — 2021-01-31
- 0.0.1 — 2021-01-31

## README

<h1 align="center">mui-rhf</h1>

<div align="center">

[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/clement-faure/mui-rhf/npm-publish)](https://github.com/clement-faure/mui-rhf/actions/workflows/npm-publish.yaml)
[![codecov](https://img.shields.io/codecov/c/github/clement-faure/mui-rhf/master.svg)](https://codecov.io/gh/clement-faure/mui-rhf/branch/master)

Quickly build powerful forms using [Material UI](https://material-ui.com/) and [React Hook Form](https://react-hook-form.com/)

</div>

## Installation

mui-rhf is available as an [npm package](https://www.npmjs.com/package/mui-rhf).

```
// with npm
npm install mui-rhf

// with yarn
yarn add mui-rhf
```

## Usage

```
import React from 'react';

import { useForm } from "react-hook-form";
import { MuiRhfForm } from "mui-rhf";
import { Button } from "@material-ui/core";

const Form = ({ onSubmit }) => {
  // Initialize form
  const { control, handleSubmit } = useForm();

  const onSubmit = (data) => {
    // Play with retrieved data
  }

  return (
    <form onSubmit={handleSubmit(onSubmit)} noValidate>
      <MuiRhfForm
        control={control}
        fields={[
          [{ name: "firstName" }, { name: "lastName" }],
          [{ name: "email" }],
          [{ name: "rememberMe", type: "checkbox" }]
        ]}
      />
      <Button type="submit">
        Submit
      </Button>
    </form>
  )
};


```

## Type

### `MuiRhfFormProps`

These are props that you pass to `<MuiRhfForm />`

#### fields: MuiRhfFormField[][];

Fields to construct the form

```
type MuiRhfFormField = {
  name: string;
  label?: string;
  props?: any;
  type?: keyof MuiRhfFieldComponentMap;
  gridProps?: Pick<GridProps, "xs" | "sm" | "md" | "lg" | "xl">;
  hideCondition?: MuiRhfFormFieldHideConditions; // Union of conditions, if true, field will be hidden
  hideConditions?: MuiRhfFormFieldHideConditions; // Intersection of conditions, if true, field will be hidden
  conditionalProps?: MuiRhfFormFieldConditionalProps; // Extra props applied depending on other form fields values
};
```

#### headers?: MuiRhfFormHeader[];

An array of titles

```
type MuiRhfFormHeader = {
  title?: string;
};
```

#### spacing?: GridSpacing;

Spacing applied to main Grid container

#### watch?: RhfWatch;

Provided by [React Hook Form](https://react-hook-form.com/api#watch)

#### control: Control;

Provided by [React Hook Form](https://react-hook-form.com/api#control)

## Contributors ✨

This project follows the
[all-contributors](https://github.com/all-contributors/all-contributors)
specification. Contributions of any kind welcome!

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