React Hook Form Tutorial (Zod + MUI) - Full Beginner to Advanced Course

Поділитися
Вставка
  • Опубліковано 23 гру 2024

КОМЕНТАРІ • 111

  • @codegenix
    @codegenix  7 місяців тому +3

    Between Formik and React Hook Form, what is your choice and why?

  • @thebocksters2756
    @thebocksters2756 6 місяців тому +3

    33:00 but Zod has its own method .email() for checking for email pattern

    • @codegenix
      @codegenix  6 місяців тому +2

      @thebocksters2756 Thanks for your amazing attention to detail! You are completely right. I was not aware of that!

  • @thisisarkajitroy
    @thisisarkajitroy 5 місяців тому +1

    Thank you so much for making this wonderful tutorial, you have covered most of the important topics, and the code structure is really clean. Please make such kind of videos more! Tanks again...

    • @codegenix
      @codegenix  5 місяців тому

      You're very welcome!

  • @waynerandom11
    @waynerandom11 7 місяців тому

    This was just incredible! It's exactly what I was looking for having had no previous experience with React Hook Form. However, as brilliant as your RHF MUI converter components are, thought I would point out that there is a 3rd party RHF-MUI wrapper library available called "react-hook-form-mui" available from the npm repository. But even so, your explanation of the RHF events, hooks, and especially its integration with Tanstack Query is invaluable. Excellent job!!

    • @codegenix
      @codegenix  7 місяців тому

      I'm so glad that you liked it🙏you made my day❤️. Also thanks for your recommended library

  • @herozero777
    @herozero777 4 місяці тому

    Thanks man. Came here from freecode video to support you. :)

    • @codegenix
      @codegenix  4 місяці тому

      I'm ready glad bro. Thanks❤️🙏

  • @KarthikMohanaKrishnan
    @KarthikMohanaKrishnan 4 місяці тому

    Thanks for sharing this tutorial, I really found it helpful. This is something I'm following and I'll recommend it to a few others as well. Thanks !

    • @codegenix
      @codegenix  4 місяці тому

      You're very welcome bro

  • @_hugo_cruz
    @_hugo_cruz 6 місяців тому

    This is the most amazing video I have ever seen on this subject, the teacher, the content, the explanation and the project is absolutely perfect, Thank you for this bro!!!!!

    • @codegenix
      @codegenix  6 місяців тому

      I'm so glad that you liked it. I really appreciate it🙏💐

  • @ВладКеся
    @ВладКеся 7 місяців тому +2

    It's amazing. In the future you might want to make a video about the best practices you use in development. Please keep it up, you're doing a very cool job.

    • @codegenix
      @codegenix  7 місяців тому

      Thanks, will do! You really made my day!

    • @ВладКеся
      @ВладКеся 7 місяців тому

      @@codegenix These videos can be divided into several parts. To make it easier to follow the course. What do you think?
      And you will be able to post more videos so that there is more activity on the channel

  • @prashlovessamosa
    @prashlovessamosa 7 місяців тому +3

    great explanation thats quite a lot i have to give my whole day i know its going to be worth it thanks buddy for sharing.

    • @codegenix
      @codegenix  7 місяців тому

      Glad to help. Just wait a little bit longer for youtube to process video in 2k quality

  • @Ernuna
    @Ernuna 5 місяців тому +1

    at 2:18:22 do we really need useEffect? looks like it will trigger unregister if isTeacher is false by default.
    do you think we can just use a function and bind it to a Switch onChange?
    function unregisterStudens() {
    if (isTeacher) return;
    replace([]);
    unregister("students");
    }

    • @codegenix
      @codegenix  5 місяців тому +1

      @Ernuna This is also a very performant solution. Just do not forget to run the onSwitchChange function in the switch controller right after the rhf onChange method.

  • @demircaner
    @demircaner Місяць тому +1

    Thank you for the great video. I really want to see a combination of React Hook Form and React Step Builder.

  • @faisal_dev951
    @faisal_dev951 5 місяців тому +2

    Man, I watched just one hour and learned so much about hooks forms! 🙌🔥 Hands down the best tutorial on earth! 🌟💯 I can't wait to complete it, but I couldn't stop myself from commenting earlier! 😄
    I have a question regarding building multi-step complex forms. What's the best approach for this? For example, if we have steps like basic info and contact info, do we need to define useForm for each step (e.g., useForm for step/basic and useForm for step/contact)? And on each page's submit, should we store the values in a Zustand store like this: { basic: {}, contact: {} }?

    • @codegenix
      @codegenix  5 місяців тому +1

      @faisal_dev951 You can't imagine how much I am glad that the tutorial is useful to you. You're very welcome.
      As stated by rhf docs itself, the way you just mentioned is totally correct, readable and really clean. I cannot think of more suitable way to achieve the same result.

  • @LeonidMaksimshin
    @LeonidMaksimshin 5 місяців тому +1

    Great tutorial! Thank you so much for the detailed explanations of extremely necessary and complex things!
    Perhaps you have some advice on how to implement a “draft” form, when not fully validated values ​​are stored in the “incomplete” status? Not sure how correct this idea is, but this approach seems to be widely applicable...

    • @codegenix
      @codegenix  5 місяців тому

      I'm so glad that you have learnt something!
      This is an amazing idea and I exactly know what you mean. This is very necessary for complex enterprise applications and requires a fully functional backend server.

    • @LeonidMaksimshin
      @LeonidMaksimshin 5 місяців тому +1

      I seem to have figured out how to do this - through the second argument 'onError' of the 'handleSubmit' function, which is called if validation fails.

    • @codegenix
      @codegenix  5 місяців тому

      @LeonidMaksimshin That's great but I suppose you got a little bit confused. The onError callback is related to React Query and is called whenever your server returns an error or the connection is not successful. If the form is not validated, React Hook Form will prevent the function passed to handleSubmit from being executed.

  • @mr.k6831
    @mr.k6831 5 місяців тому +1

    Thank you so much for this amazing video. 😍😍😍😍😍😍

  • @dedanmsafari8213
    @dedanmsafari8213 6 місяців тому +2

    cool tutorial.I loved it.Alot of concepts learned.Really looking forward to your tutorials.side note: I noted the parse function didnt exactly log the exact issue as is case with your browser. It only gave a generic message.

    • @codegenix
      @codegenix  6 місяців тому +1

      Yes, you are right. I'm so glad that you liked it

  • @Ernuna
    @Ernuna 5 місяців тому +1

    thank you for such a great tutorial.
    for some reason I am stuck with two errors, I was wondering if you are experiencing the same because they are sort of silent error that dont break anything but smth is not right:
    1 - first is in DevTools is related to changing isTeacher from false to true
    isTeacher
    ERROR Type:
    invalid_literal
    MESSAGE:
    Invalid literal value, expected false
    Value:
    true
    Touched: false
    Dirty: true
    2 - second is in console whenever we populate new student name field:
    Cannot update a component (`DevTool`) while rendering a different component (`Users`).

    • @Ernuna
      @Ernuna 5 місяців тому +1

      btw in order to avoid first error do you think it is a good idea to use discriminated union instead of normal union? because our array is dependant on isteacher value
      const teacherSchema = baseUserSchema.extend({
      isTeacher: z.literal(true),
      students: z.array(
      z.object({
      name: z.string().min(1, { message: "Name is required" }),
      })
      ),
      });
      const nonTeacherSchema = baseUserSchema.extend({
      isTeacher: z.literal(false),
      });
      export const userSchema = z.intersection(
      z.discriminatedUnion("isTeacher", [teacherSchema, nonTeacherSchema]),
      // rest for variant
      );

    • @codegenix
      @codegenix  5 місяців тому

      @Ernuna I hope you have enjoyed the tutorial.
      Are you talking about the devtools of react hook form or the console tab of your browser?

    • @Ernuna
      @Ernuna 5 місяців тому +1

      @@codegenix react hook form devtools

    • @codegenix
      @codegenix  5 місяців тому +1

      @Ernuna I don't recommend using the rhf devtools for complex scenarios. It is not accurate and is not synced with zod perfectly. To log the current values of the form with performance in mind, I suggest using this hook:
      function useFormLogger() {
      const { watch } = useFormContext();
      useEffect(() => {
      const { unsubscribe } = watch((value) => console.log(value));
      return unsubscribe;
      }, [watch]);
      }
      function Provider() {
      const methods = useForm();
      return (

      );
      }
      function Form() {
      useFormLogger();
      return {/* Your form */};
      }

  • @harrisonwell1719
    @harrisonwell1719 5 місяців тому +1

    I'm trying to validate any array of objects, like an invoice and invoice details, any idea how to do that?, thanks.

    • @codegenix
      @codegenix  5 місяців тому

      @harrisonwell1719 Would you be more specific? I can help you if possible

    • @harrisonwell1719
      @harrisonwell1719 5 місяців тому

      @@codegenix ok, so I have an object purchase order and it has it’s properties including an array of purchase order items how can I validate this object “purchase order”

  • @kong-0214
    @kong-0214 4 місяці тому

    Great tutorial. If I need to store objects removed from useFieldArray remove method to another array for subsequent use. How can I achieve this?

    • @codegenix
      @codegenix  4 місяці тому +1

      @user-se6mi3fe8w I'm glad you liked it! Would you explain more about your problem? Maybe I can help you.

    • @kong-0214
      @kong-0214 4 місяці тому

      @@codegenix How can I send you the codes I have problems with? I find I can't post codes here.

  • @xaos1704
    @xaos1704 7 місяців тому +1

    Great work, Could you show how add useTranslation from "react-i18next"; to schema ? :)

    • @codegenix
      @codegenix  7 місяців тому +1

      Great suggestion! I am working on a complete full stack multilingual tutorial.

  • @dharylalmora3121
    @dharylalmora3121 4 місяці тому +1

    @3:13 i was the one in 92.5%.
    but n0w done subscribe!

    • @codegenix
      @codegenix  4 місяці тому

      Appreciate it bro❤️

  • @TamerlanKengerli
    @TamerlanKengerli 7 місяців тому

    Great video. But I have a question. Couldn't we just use z.string().email() for email validation?

    • @codegenix
      @codegenix  7 місяців тому +1

      I really appreciate it. Yes, absolutely. I just wanted to show you how to use custom validations for different fields using refine and I just used the email field as an example. Now I realized that zod also has a validation for email!😁 But both of them are correct

  • @Akash-xv5sk
    @Akash-xv5sk 6 місяців тому +1

    What if i have multiple forms in a project, Do I have to create separate schema for each form?

  • @devT44
    @devT44 7 місяців тому +1

    Sir, I am newly started learning reactjs. Thank you so much for posting this tutorial.
    I have a problem in using devtools properly. Will u make such a highquality video on devtools?

    • @codegenix
      @codegenix  7 місяців тому +1

      What a great idea! Sure my friend.
      Also I hope you enjoy learning react and thank you for your positive feedback.

    • @codegenix
      @codegenix  7 місяців тому

      The video is still processing by UA-cam. The 2k quality will be ready in a few hours...

  • @Ernuna
    @Ernuna 4 місяці тому +1

    do you know if discriminated union can be replicated in yup?

    • @codegenix
      @codegenix  4 місяці тому

      @Ernuna I'm not sure. But handling unions and intersections in schema is pretty straighforward.

  • @fagnermenezes5415
    @fagnermenezes5415 7 місяців тому

    Hi Code Genix, awesome video!
    Can you make a video about internationalization projects? Using tools like i18n for example and next.js or React
    I tried to create a project with 2 languages in nextjs but I couldn't

    • @codegenix
      @codegenix  7 місяців тому +1

      I'm glad you liked it! The Next.js docs has great explanation about how to handle the scenario you just mentioned without any third party library

  • @kong-0214
    @kong-0214 7 місяців тому

    Why are there no examples of MUI Select and file upload?

    • @codegenix
      @codegenix  7 місяців тому +1

      File upload is a good idea. If there are more request on it, I'm gonna create a video on it

    • @kong-0214
      @kong-0214 6 місяців тому

      @@codegenix File upload is frequently used in projects. I'm looking forward to your videos. Thanks.

  • @regilearn2138
    @regilearn2138 3 місяці тому +2

    please do redux toolkit practical video

    • @codegenix
      @codegenix  3 місяці тому +1

      The combination of Zustand and react query is a very common pattern nowadays. Redux can be really overkill for most of the scenarios

    • @regilearn2138
      @regilearn2138 3 місяці тому +1

      @@codegenix ok Appreciate your reply , so then please consider real would project the combination of Zustand and react query with hook form with postgre database

  • @P3ltor
    @P3ltor 7 місяців тому

    Great tutorial mashti!

  • @msarlak1512
    @msarlak1512 6 місяців тому +1

    awesome dadash.

  • @activelistener4484
    @activelistener4484 7 місяців тому +4

    Subscribed and added to "Watch later" playlist. Hope video get re-uploaded to high resolution.

    • @codegenix
      @codegenix  7 місяців тому +1

      Glad you liked it! The UA-cam is still processing the video. You can watch it in 2k resolution in a few hours.

    • @rea_kr
      @rea_kr 7 місяців тому

      @@codegenix That's a very good news!

    • @codegenix
      @codegenix  7 місяців тому +1

      I Appreciate it😅

  • @leviathanxid
    @leviathanxid 7 місяців тому +1

    Hallo sir ,can you make full tutorial of using prisma in next js

    • @codegenix
      @codegenix  7 місяців тому

      That's a great idea! Sure my friend.

    • @codegenix
      @codegenix  7 місяців тому

      The UA-cam is still processing the video. You can watch it in 2k resolution in a few hours.

  • @lamtran6520
    @lamtran6520 7 місяців тому +1

    Love the video

    • @codegenix
      @codegenix  7 місяців тому +1

      Glad you enjoyed!

  • @bilal5488
    @bilal5488 7 місяців тому +1

    Is typescript is necessary coz I don't know typescript

    • @codegenix
      @codegenix  7 місяців тому +1

      In modern front-end web development, typescript is very recommended and some scenarios (for example developing a complex admin dashboard) is not possible with javascript. So I really recommend you to learn it. It's the same as javascript but with some type safety!

    • @bilal5488
      @bilal5488 7 місяців тому +1

      @@codegenix yeah i have plans for that but at this time am not a senior one at this point am making MERN first or sec project after that i want to move towards typescript and nextjs or also you can recommend me something

    • @codegenix
      @codegenix  7 місяців тому

      That's an amazing plan. Just fully learn the javascript & react then move to typescript and nextjs.

  • @patolorde
    @patolorde 7 місяців тому

    Can you do one with shadcn/ui, i have a hard time integrating all features and you go really advanced. (shadcn uses a bit of tanstack as well)

    • @codegenix
      @codegenix  7 місяців тому +1

      It's on my schedule sir. Thanks for your suggestion.

    • @patolorde
      @patolorde 7 місяців тому

      Thanks! Subscribed

  • @parsamajd2788
    @parsamajd2788 5 місяців тому +1

    are you persion?

  • @minhajul-me
    @minhajul-me 7 місяців тому +1

    thanks

  • @smartdriver2990
    @smartdriver2990 7 місяців тому

    Thanks for this tutorial

  • @kamill34
    @kamill34 7 місяців тому

    you are great!!!

    • @codegenix
      @codegenix  7 місяців тому

      I'm really glad you liked it!

  • @yoyomomma
    @yoyomomma 7 місяців тому

    ❤ Thank you!

    • @codegenix
      @codegenix  7 місяців тому

      You're very much welcome!

  • @adityashinde7815
    @adityashinde7815 6 місяців тому

    Nice video

    • @codegenix
      @codegenix  6 місяців тому

      Glad you liked it

  • @casull6447
    @casull6447 7 місяців тому

    thank you for video !

    • @codegenix
      @codegenix  7 місяців тому +1

      You are welcome! The video is still processing by UA-cam. The 2k quality will be ready in a few hours.

  • @rezwanulhaque9935
    @rezwanulhaque9935 7 місяців тому +1

    great

    • @codegenix
      @codegenix  7 місяців тому

      I'm glad it was helpful

  • @이너피스-o1c
    @이너피스-o1c 7 місяців тому

    awesome!

    • @codegenix
      @codegenix  7 місяців тому

      Glad you think so!

  • @rezwanulhaque9935
    @rezwanulhaque9935 7 місяців тому +2

    Sir Can You give us a React+ Tailwind project which can be included React router Dom, REact Hook Form, context APi, React Transtak Query and some animations. Using above these materials we will be helpful sir. If possible pls sir show a Great project using above tools or add some more functions if you assume.

    • @codegenix
      @codegenix  7 місяців тому +1

      That's an amazing suggestion. I am currently working on a full stack e-commerce project with nextjs prisma and other things that you suggested

    • @rezwanulhaque9935
      @rezwanulhaque9935 7 місяців тому +1

      @@codegenix thanks.pls use Tailwind css, and React Transtak Query

    • @codegenix
      @codegenix  7 місяців тому +1

      Always!

  • @thebocksters2756
    @thebocksters2756 6 місяців тому +2

    u r teaching as how to properly build things, but don't teach as how this things works and why we should do it this way. I am specificaly talking about the Controller section

    • @codegenix
      @codegenix  6 місяців тому +1

      @thebocksters2756 Image you have a form containing more than 50 form fields (text fields, auto completes, radio buttons and...), encapsulating the form fields logic (passing data between the MUI component fields and RHF controls) can be a lifesaver. Defining a controller for each mui component in each usage is not maintainable. Therefore, we create different controllers for each form field as needed for encapsulation and better maintainability then we use those controllers anywhere that we want.