2023-06-08
2977
#react
Mohammad Faisal
62692
Jun 8, 2023 ⋅ 10 min read

Using Material UI with React Hook Form

Mohammad Faisal I am a full-stack software engineer working with the MERN stack. Also, I am a blogger in my free time and love to write about various technical topics.

Recent posts:

master state management hydration Nuxt usestate

Nuxt state management and hydration with useState

useState can effectively replace ref in many scenarios and prevent Nuxt hydration mismatches that can lead to unexpected behavior and errors.

Yan Sun
Jan 20, 2025 ⋅ 8 min read
React Native List Components: FlashList, FlatList, And More

React Native list components: FlashList, FlatList, and more

Explore the evolution of list components in React Native, from `ScrollView`, `FlatList`, `SectionList`, to the recent `FlashList`.

Chimezie Innocent
Jan 16, 2025 ⋅ 4 min read
Building An AI Agent For Your Frontend Project

Building an AI agent for your frontend project

Explore the benefits of building your own AI agent from scratch using Langbase, BaseUI, and Open AI, in a demo Next.js project.

Ivaylo Gerchev
Jan 15, 2025 ⋅ 12 min read
building UI sixty seconds shadcn framer ai

Building a UI in 60 seconds with Shadcn and Framer AI

Demand for faster UI development is skyrocketing. Explore how to use Shadcn and Framer AI to quickly create UI components.

Peter Aideloje
Jan 14, 2025 ⋅ 6 min read
View all posts

16 Replies to "Using Material UI with React Hook Form"

  1. I changed the FormInputText because there is no code in the return.

    Sharing my result. Thank u. Nice article!

    import TextField from ‘@mui/material/TextField’;
    import { Controller } from “react-hook-form”;

    export const FormInputText = ({ name, control, label }) => {

    return (

    }
    />
    )

    }

  2. Thanks for the writeup. I’m a bit baffled on your approach with hook-form, how come you opted to make the control approach for these? I would have preferred the register method much more for known frameworks that behave nicely with hook-form. Sure, in case where specific control is needed I see the controller as the choice, but for most of the examples register would have entirely sufficed. Once more, thanks for the writeup, I seem to return to your texts often enough.

    1. What I’ve seen is that with Material UI you can’t do register because MUI components are controlled components, so you have to wrap a controller around them. It feels really messy to do it to be honest.

  3. Can’t we just create a simple FormField component instead of creating FormInputText, FormInputSlider etc. ?

  4. Thank you for the published content. It is extremely important because this is a difficulty that many devs face when controlling inputs from other libraries.

  5. This is really helpful thanks. One thing i want to mention that Autocomplete is missed. which is most important in my project. Also I work with custom component. so set controller into main component only. but what if we no need react-hook-form in some places, in my case parent component stick with controller. so have to mention it in all forms.

  6. Great article! Could you please provide the type definition for FormInputProps? It’s not available in the code samples above.

      1. Just to complement, to use the most appropriate typing:

        import { type Control, Controller, type FieldValues } from ‘react-hook-form’

        interface FormInputProps {
        name: string
        control?: Control
        label?: string
        }

Leave a Reply