7.0.0 • Published 4 days ago

react-hook-form-mui v7.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 days ago

Material-UI and react-hook-form combined

GitHub Average time to resolve an issue Percentage of issues still open

About this project

This project simplifies the use of react-hook-form and Material-UI. It provides opinionated use cases with following components:

  • FormContainer
  • AutocompleteElement
  • TextFieldElement
  • SelectElement
  • MultiSelectElement
  • RadioButtonGroup
  • CheckboxButtonGroup
  • CheckboxElement
  • SwitchElement
  • PasswordElement
  • DatePickerElement
  • SliderElement
  • ToggleButtonGroupElement

Please check out the demo for the element overview.

How to use it

Installation

# npm install react-hook-form react-hook-form-mui
# yarn add react-hook-form react-hook-form-mui

This package utilizes pickers and icons of the MUI ecosystem. If you make use of it add them to your app.

#  npm install @mui/x-date-pickers @mui/icons-material
#  yarn add @mui/x-date-pickers @mui/icons-material

Important

From versions >= 3.x of this package MUI v5 is in use. Versions of 1 & 2 using Material-UI v4

Your component code

import {FormContainer, TextFieldElement} from 'react-hook-form-mui'

function Form() {
    return (
        <FormContainer
            defaultValues={{name: ''}}
            onSuccess={data => console.log(data)}
        >
            <TextFieldElement name="name" label="Name" required/>
        </FormContainer>
    )
}

You can have a look at the example folder which sets up NextJS with react-hook-form-mui

FormContainer creates formContext

The <FormContainer /> wires up a form and you can create sub-components which either make use of useFormContext() | useWatch() to react to form values.

Demo

Check out Storybook: Demo

You will find examples and use cases.

With Datepicker

If you are using the DatepickerElement keep in mind that you have to wrap your form with a provider:

Examples for Dayjs or DateFns provider (used in the demo):

Troubleshooting

Issues if context is undefined (useWatch)

For convenient reasons this package is re-exporting react-hook-form which is especially required if you have context issues of React.

import {useWatch} from 'react-hook-form-mui' // instead of react-hook-form

const MySubmit = () => {
    const value = useWatch('fieldName')
    return (
        <Button disabled={!value}>Submit</Button>
    )
}

Bundle

This project uses tsup to wrap the package for npm.

7.0.0

4 days ago

7.0.0-beta.4

30 days ago

7.0.0-beta.2

1 month ago

7.0.0-beta.3

1 month ago

7.0.0-beta.1

1 month ago

7.0.0-beta.0

4 months ago

6.8.0

4 months ago

6.6.1

6 months ago

6.6.0

6 months ago

6.6.2

6 months ago

6.7.0

6 months ago

6.7.2

5 months ago

6.5.4

6 months ago

6.7.1

6 months ago

6.5.3

6 months ago

6.7.3

5 months ago

6.5.2

8 months ago

6.3.0

11 months ago

6.1.1

12 months ago

6.5.0

9 months ago

6.3.1

11 months ago

6.4.2

10 months ago

6.2.0

11 months ago

6.4.1

10 months ago

6.4.0

10 months ago

6.5.1

9 months ago

6.1.0

12 months ago

5.15.0

1 year ago

5.13.2

1 year ago

5.13.1

1 year ago

5.16.0

1 year ago

5.12.4

1 year ago

6.0.1

1 year ago

6.0.0

1 year ago

5.14.0

1 year ago

5.15.1

1 year ago

5.11.0

1 year ago

5.8.0

1 year ago

5.12.3

1 year ago

5.12.2

1 year ago

5.12.1

1 year ago

5.12.0

1 year ago

5.10.2

1 year ago

5.10.1

1 year ago

5.6.0

2 years ago

5.7.2

2 years ago

5.7.1

2 years ago

5.7.0

2 years ago

5.5.1

2 years ago

5.5.0

2 years ago

5.4.1

2 years ago

5.3.2

2 years ago

5.4.0

2 years ago

5.3.1

2 years ago

5.3.0

2 years ago

5.2.0

2 years ago

5.1.0

2 years ago

5.0.0

2 years ago

3.5.7

2 years ago

3.5.6

2 years ago

3.9.1

2 years ago

3.5.5

2 years ago

3.9.0

2 years ago

3.5.4

2 years ago

3.4.0

2 years ago

3.3.0

2 years ago

3.8.0

2 years ago

3.5.3

2 years ago

3.7.0

2 years ago

3.5.2

2 years ago

3.6.0

2 years ago

3.5.1

2 years ago

3.5.0

2 years ago

4.1.0

2 years ago

4.0.0

2 years ago

3.1.3

2 years ago

3.2.1

2 years ago

3.2.0

2 years ago

3.1.5

2 years ago

3.1.4

2 years ago

3.1.2

2 years ago

3.1.1

2 years ago

3.1.0

2 years ago

3.0.0

2 years ago

2.0.7

3 years ago

2.1.0

3 years ago

2.0.5

3 years ago

2.0.6

3 years ago

2.0.4

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago