Installations
npm install react-hook-form-mui
Releases
MUI pickers version 6 and some more improvements
Published on 30 Mar 2023
Add readonly prop to DatePicker and DateTimePicker
Published on 18 Nov 2022
Add DateTimePicker
Published on 14 Nov 2022
Support small prop on MultiSelectElement
Published on 15 Sept 2022
New Component
Published on 30 Aug 2022
Restructure Repo as Monorepo and re-export react-hook-form API
Published on 29 Aug 2022
Developer
Developer Guide
Module System
CommonJS, ESM
Min. Node Version
>=14
Typescript Support
No
Node Version
20.10.0
NPM Version
9.6.6
Statistics
562 Stars
534 Commits
111 Forks
10 Watching
3 Branches
36 Contributors
Updated on 25 Nov 2024
Bundle Size
27.61 kB
Minified
7.82 kB
Minified + Gzipped
Languages
JavaScript (98.39%)
TypeScript (1.31%)
HTML (0.3%)
CSS (0.01%)
Total Downloads
Cumulative downloads
Total Downloads
1,832,534
Last day
-14.8%
4,613
Compared to previous day
Last week
-5.1%
25,092
Compared to previous week
Last month
5.6%
111,998
Compared to previous month
Last year
82.4%
1,102,942
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
5
Material-UI and react-hook-form combined
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
- DateTimePickerElement
- SliderElement
- ToggleButtonGroupElement
Please check out the demo for the element overview.
How to use it
Installation
1# npm install react-hook-form react-hook-form-mui 2# 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.
1# npm install @mui/x-date-pickers @mui/icons-material 2# 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
From version >= 6 x-date-pickers version 6 is in use. Make sure you upgrade your dependencies.
Simple form setup
1import {FormContainer, TextFieldElement} from 'react-hook-form-mui' 2 3function Form() { 4 return ( 5 <FormContainer 6 defaultValues={{name: ''}} 7 onSuccess={data => console.log(data)} 8 > 9 <TextFieldElement name="name" label="Name" required/> 10 </FormContainer> 11 ) 12}
Typesafe form setup
1 function Form() { 2 const {control, handleSubmit} = useForm({ 3 defaultValues: { 4 name: '', 5 auto: '', 6 check: false 7 }, 8 }) 9 const options = [ 10 {id: 'one', label: 'One'}, 11 {id: 'two', label: 'Two'}, 12 {id: 'three', label: 'Three'}, 13 ] 14 return ( 15 <form onSubmit={handleSubmit((data) => console.log(data))} noValidate> 16 <Stack spacing={2}> 17 <TextFieldElement 18 name={'name'} 19 label={'Name'} 20 control={control} 21 required 22 fullWidth 23 /> 24 <AutocompleteElement 25 name={'auto'} 26 label={'Autocomplete'} 27 control={control} 28 options={options} 29 /> 30 <CheckboxElement name={'check'} label={'Check'} control={control} /> 31 <Button type={'submit'} color={'primary'}> 32 Submit 33 </Button> 34 </Stack> 35 </form> 36 ) 37 }
You can have a look at all different possibilities to use forms at following code examples
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.
1import {useWatch} from 'react-hook-form-mui' // instead of react-hook-form 2 3const MySubmit = () => { 4 const value = useWatch('fieldName') 5 return ( 6 <Button disabled={!value}>Submit</Button> 7 ) 8}
Bundle
This project uses tsup
to wrap the package for npm
.
Support Maintanance
If you find this package useful consider a small contribution: Buy Me A Coffee
Contributing
Make sure you're running Node.js 20
- Clone this repository
1git clone https://github.com/dohomi/react-hook-form-mui.git 2cd react-hook-form-mui
- Install dependencies
1yarn
- Build the project
1yarn build
- Run the storybook
1yarn sb-start
Changes to storybook stories can be made in apps/storybook/stories
. Changes to the library can be made in packages/rhf-mui
.
No vulnerabilities found.
Reason
30 commit(s) and 7 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 6/14 approved changesets -- score normalized to 4
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/dohomi/react-hook-form-mui/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/dohomi/react-hook-form-mui/ci.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:31: update your workflow using https://app.stepsecurity.io/secureworkflow/dohomi/react-hook-form-mui/ci.yml/master?enable=pin
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 22 are checked with a SAST tool
Reason
11 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-9vvw-cc9w-f27h
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97
- Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp
- Warn: Project is vulnerable to: GHSA-4wx3-54gh-9fr9
- Warn: Project is vulnerable to: GHSA-r683-j2x4-v87g
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
Score
3.8
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to react-hook-form-mui
react-hook-form
Performant, flexible and extensible forms library for React Hooks
@hookform/resolvers
React Hook Form validation resolvers: Yup, Joi, Superstruct, Zod, Vest, Class Validator, io-ts, Nope, computed-types, TypeBox, arktype, Typanion, Effect-TS and VineJS
@rjsf/mui
Material UI 5 theme, fields and widgets for react-jsonschema-form
@mui/private-theming
Private - The React theme context to be shared between `@mui/styles` and `@mui/material`.