npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mui-hook-form-mhf

v1.0.2

Published

Component library to streamline and simplify the use of Material UI (MUI) and React-Hook-Form

Downloads

9

Readme

Mui-Hook-Form (MHF)

MHF is an opinionated use case of React Hook Form (react-hook-form / RHF) and Material UI v5 (@mui/material / MUI) written in TypeScript. MHF attempts to simplify and streamline the use of RHF and MUI by providing a set of components that users can use just as if they were normal MUI input components. Each component supports majority of MUI's components props and also RHF Controller's 'rules' prop. Additionally, all of the components are meant to be used as Uncontrolled components enabling RHF to handle all underlying state.

As a reminder, MHF can only be used if react-hook-form (RHF), MUI (@mui/material), and @mui/x-date-pickers have been installed

The following components are presented within this library:

  • MHFAutocomplete
  • MHFCheckbox
  • MHFDatePicker
  • MHFLabeledCheckbox
  • MHFLabeledSwitch
  • MHFMultipleSelect
  • MHFRadioButtonGroup
  • MHFRating
  • MHFSelect
  • MHFTextField
  • MHFTimePicker

In order to use the MHFTimePicker or MHFDatePicker components, they must be wrapped in a LocalizationProvider. For more information, see https://mui.com/x/react-date-pickers/getting-started/ .

Implementation

For a more detailed look into each component and what it may offer please visit the library's dedicated Storybook at https://mui-hook-form-mhf.netlify.app/?path=/story/introduction--page . Additionally, for more information about specific MUI prop implementation, please visit the corresponding MUI Component Docs for the component. Below will only present a very basic example of how to implement the library into your own component.

npm install mui-hook-form-mhf

Each component is wrapped in the React-Hook-Form's Controller component. For that reason, each component will need to be passed a control from the useForm hook. Besides the name and control prop, each component within the libray behaves just as a regular MUI component would. The only difference is that the components are meant to be used an Uncontrolled Component. The storybook docs go in further detail about the implementation.

import { MHFTextField } from 'mui-hook-form-mhf';
import { useForm } from 'react-hook-form';

const Component = () => {
  const methods = useForm();

  const onSubmit = (data) => {
    console.log(data);
  };

  return (
    <form onSubmit={methods.handleSubmit(onSubmit)}>
      <MHFTextField name="MHFTextField" control={methods.control} />
    </form>
  );
};

Components such as MHFLabeledCheckbox and MHFLabeledSwitch are implemented using MUI's FormControlLabel component, so if you would like to create a group. It can easily be done by wrapping the component with a FormGroup component like below

<FormGroup>
  <MHFLabeledCheckbox
    name="MHFLabeledCheckbox"
    control={methods.control}
    label="MHFLabeledCheckbox"
  />
</FormGroup>

Links

Change Log

  • (1.0.1) Added variant prop to MHFDatePicker.