Quickly build powerful forms using Material UI and React Hook Form
mui-rhf is available as an npm package.
// with npm
npm install mui-rhf
// with yarn
yarn add mui-rhf
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>
)
};
These are props that you pass to <MuiRhfForm />
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
};
An array of titles
type MuiRhfFormHeader = {
title?: string;
};
Spacing applied to main Grid container
Provided by React Hook Form
Provided by React Hook Form
This project follows the all-contributors specification. Contributions of any kind welcome!