React Forms Full Tutorial - Validation, React-Hook-Form, Yup

Поделиться
HTML-код
  • Опубликовано: 1 ноя 2024

Комментарии • 165

  • @monikabhardwaj9105
    @monikabhardwaj9105 3 года назад +8

    A very good tutorial. Because of the new version release there are few changes that we have to do.
    1. Error is now a part of formState so use it like below instead of const{register, handleSubmit,errors}
    const{register,handleSubmit,formState: { errors }} =useForm({
    resolver:yupResolver(schema),
    });
    2. replace ref={register} to {...register("phone_number")} , replace "phone_number" with the name of your field.

  • @gotemperory4278
    @gotemperory4278 3 года назад +54

    what worked for me is:
    const { register, handleSubmit, formState: { errors } } = useForm({
    resolver: yupResolver(schema),
    });
    instead of
    const { register, handleSubmit, errors } = useForm({
    resolver: yupResolver(schema),
    });
    and
    {...register('password')}
    instead of
    ref={register}

    • @PedroTechnologies
      @PedroTechnologies  3 года назад +4

      Appreciate it! This is the new updated version!

    • @hmsm5701
      @hmsm5701 3 года назад

      thanks a lot

    • @akhiltheloquacioussoul
      @akhiltheloquacioussoul 3 года назад

      Thank you so much :)

    • @andriitsvirko7296
      @andriitsvirko7296 3 года назад

      thanks a lot!!!!!!!!!!!!!!

    • @TheRonron1994
      @TheRonron1994 3 года назад

      I'm getting this error instead
      Error: Function components cannot have string refs. We recommend using useRef() instead.

  • @df15804
    @df15804 3 года назад +23

    It is amazing to see this kind of content coming from a Brazilian guy, thank you there

    • @PedroTechnologies
      @PedroTechnologies  3 года назад +10

      Hahaha thank you so much! Brazil needs to grow in the programming community!

  • @guythomas5391
    @guythomas5391 2 года назад +7

    This is an excellent tutorial, thank you! One small criticism - it's not good practice to rely solely on front end validation, so I would revise the comment in this video "You can safely make a fetch request... and it should be completely safe because you're only submitting the data if it passes through the layer of validation". Someone could easily craft a request via postman or something and submit direct to your server. Always employ server validation.

  • @mpv756
    @mpv756 2 года назад +1

    Great video! I'm just learning react. The course I was taking used redux-form \ redux. I was trying to do the right thing (I think) and make a radio button it's own component so it could be shared in any form. It was a nightmare because of all the state management between components. I never did get it to work. So I was ready to try something new, even if I can't make the radio button it's own component (I'm sure you can). A google search of what are the best libraries for forms got me to react-hook-forms, which led me here. Thank you so much for showing everything from beginning to end. Very helpful and useful.

  • @Mahdi-lz9wu
    @Mahdi-lz9wu 3 года назад

    thank you, buddy,
    find a good solution after 3 days of struggling with form and validation.
    just react-hook-from had changed to version 7 and it needs some small change but this tutorial is absolutely brilliant.

  • @anikinae
    @anikinae 2 года назад

    perfect speach (not too slowly and not too fast) - thank you so much, it's very useful!

  • @fancyAlex1993
    @fancyAlex1993 3 года назад +2

    In v7, it should be like this , replace ref with an obj like this

    {errors.firstName?.message}
    Thank you for this tutorial. I was getting tired reading the react-hook-form documentation.

    • @ak2000_
      @ak2000_ 3 года назад

      TypeError: Cannot read properties of undefined (reading 'firstName')

  • @linmus2370
    @linmus2370 3 года назад +3

    You're so badass! I'll go out on limb and say that your channel is gonna have millions of subscribers. I do have a feeling of that. The efforts you're exerting into the videos you're cranking out are gonna pay off. It's a top-tier channel. You're freaking killing it. Love from the US.

    • @PedroTechnologies
      @PedroTechnologies  3 года назад

      Hahaha I love this kind of comments! Thank you so much! I really appreciate the support!

  • @iqra.manzoor4222
    @iqra.manzoor4222 2 года назад +3

    I am using the same code with react version 18.1.0.But it is not working, browser is displaying white screen.How can I resolve this issue?

  • @AnthonyCandaele
    @AnthonyCandaele 2 года назад

    Thanks for this video, the combination of react-hook-form and yup is just what I need for the form validation in my next project.

  • @ayushdedhia25
    @ayushdedhia25 3 года назад +6

    Your tutorials are just amazing and easy to grasp the concept ❤️🔥

  • @marimuthur9456
    @marimuthur9456 2 года назад

    Extraordinary explanation thank you so much for your knowledge sharing 😊👌🏼🙏🏼 try to post the video how to bind the form data back to the input fields using yup

  • @adennis200
    @adennis200 3 года назад +3

    Not gonna watch it right now cause no time but I'm gonna like it in advance

    • @PedroTechnologies
      @PedroTechnologies  3 года назад +1

      Hahaha this makes me happy! Really appreciate the support!

  • @Trzimajewski
    @Trzimajewski 2 года назад +3

    Mano, ótimo conteúdo, parabéns.
    Muito bom saber que existe conteúdo de qualidade assim e que é brasileiro que faz, te desejo muito sucesso.

  • @marbot9780
    @marbot9780 3 года назад +1

    Hello Pedro,
    I am a big fan of your videos here!
    Thanks for this one - it is amazing!
    Could you please also show how to split the form here into a multi-form (at least 3 input steps) and everything then still works - including validation!?
    That you can e.g. only jump on if everything is correct and that you don't lose any values when jumping back!
    There are already videos about it - but they are all incomplete or incorrect!
    Thanks in advance!
    Best regards
    Markus

  • @anshunarayan8056
    @anshunarayan8056 Год назад

    Although you are speaking in an american accent but your lectures are too easy to understand😊

  • @Jiji-lo3zs
    @Jiji-lo3zs 2 года назад

    I finally understood react-hook-forms. Thankyou 🙂

  • @perfectionist2518
    @perfectionist2518 Год назад

    mate, you got a talent! thank you, it was simple and clear

  • @DimmuBorgiry
    @DimmuBorgiry 3 года назад

    thanks my friend, it was really a helpful video for me to get into react hook forms. keep up the good work

  • @junjietan2668
    @junjietan2668 3 года назад +2

    Keep on going Pedro, your videos helps me a lot. Appreciate your hard work!

    • @PedroTechnologies
      @PedroTechnologies  3 года назад +1

      Happy to hear that! This comments motivate me a lot!

    • @junjietan2668
      @junjietan2668 3 года назад

      @@PedroTechnologies no worry pedro. Meanwhile, i have a barrier after working on the form. it is working fine in the form validation. however comes to form submission, the function was not working even though the password is matched. I noticed if i have remove the resolver from useform, it is working fine as the console will printed out the outcomes however the password and Cpassword have no validation. then, if i implment the resolver onsubmit function does not fire up at all. What's the problem? Many thanks.

    • @muradjadoon619
      @muradjadoon619 Год назад

      @@PedroTechnologies I like your videos

  • @andrscrrn
    @andrscrrn 2 года назад +1

    Very clear explanantion! Thanks Pedro!

  • @sinaukode
    @sinaukode 3 года назад

    Thanks, it's really helpful for me who just started to learn react stuff

  • @dennisbelio6470
    @dennisbelio6470 3 года назад +1

    Thank you PedroTech for this wonderful resource!

  • @hamidrezahassanzadeh246
    @hamidrezahassanzadeh246 2 года назад

    Hi dear Pedro!
    Actually I want to thank you for this really really well-described content , you helped me a lot my bro ❤

  • @caikhenrik10
    @caikhenrik10 3 года назад +3

    Pedro, muito bom vídeo! Mais um inscrito pra ti...
    Uma sugestão pro próximo vídeo, fazer validação de arquivos com o yup e react hook form... verificar se o arquivo é muito longo, formato, etc... Ajudaria bastante! Top

    • @caikhenrik10
      @caikhenrik10 3 года назад +1

      No caso upload de arquivos*

    • @PedroTechnologies
      @PedroTechnologies  3 года назад +2

      Obrigado! Você quer dizer validar arquivos que sao uploaded?

    • @caikhenrik10
      @caikhenrik10 3 года назад +1

      @@PedroTechnologies isso! Por exemplo validar se o arquivo é uma imagem, e se a imagem não excede determinada altura e largura por exemplo, seria top!

  • @bluebill1049
    @bluebill1049 3 года назад +2

    Thank you very much for putting up this video tutorial!

  • @wilhelm.reeves
    @wilhelm.reeves 3 года назад

    Your videos are very easy to follow.
    Thank you 🥂

  • @mohamedabdulqadir2917
    @mohamedabdulqadir2917 3 года назад +1

    Your tutorials really amazing, thank you Pedro

  • @harshitverma4480
    @harshitverma4480 2 года назад

    Very clear n concise explanation.

    • @vinayr6232
      @vinayr6232 2 года назад

      Hey Harshit!
      Glad you liked the video.....would you be interested in exploring opportunities in web development?

  • @anmolgarg7038
    @anmolgarg7038 Год назад

    Amazing tutorial, really well described. Loved it .

  • @aneeqrehman4138
    @aneeqrehman4138 3 года назад +1

    thumbs UP!.... Q# what is the best way to design our components in a project......either we use styled-componnets,scss or css......?

    • @PedroTechnologies
      @PedroTechnologies  3 года назад +1

      I like to use styled-components! There is no best way, it is all about preference!

    • @aneeqrehman4138
      @aneeqrehman4138 3 года назад

      @@PedroTechnologies plz share the link where you have design a full dynamic tamplate using style...

  • @minsungsuh3872
    @minsungsuh3872 2 года назад

    Thank you for this useful video! Is there a way to style the error messages?

  • @thiagoleobons390
    @thiagoleobons390 3 года назад +3

    Maneiro o canal cara. Parabens!

  • @dedekinc
    @dedekinc 2 года назад +1

    ./src/Components/Form.js
    Module not found: Can't resolve '@hookform/resolvers/yup' in 'C:\Users\uscr\Desktop\letreact\src\Components'

  • @jenslegrou
    @jenslegrou 3 года назад +2

    This is gold. Thank you so much!

  • @thrivingproject1920
    @thrivingproject1920 2 года назад

    Hey, great vid; what's the extension you use that formats the JS document around 18:13?

  • @kofinartey116
    @kofinartey116 3 года назад

    Thanks a lot for this sir. You helped out a brother

  • @skverskk
    @skverskk 2 года назад

    Well done and easy to understand. Thx

  • @ThColinPereira
    @ThColinPereira 3 года назад

    This helped me a lot, thanks Pedro!

  • @CarlWicker
    @CarlWicker 2 года назад

    THanks for this, great tutorial.

  • @antenehyehalem5963
    @antenehyehalem5963 3 года назад +2

    heyy another awesome video from hero keep doing it

  • @brosethkator7246
    @brosethkator7246 2 года назад +1

    Hi
    PedroTech, what extension you use to detect file size when import library? Eg: import React from "react"; this part -> "7. 2K (gzipped: 2.9K)
    "
    Thanks.

  • @safintheship
    @safintheship 2 года назад +1

    thank you so much dude

  • @fionagonza8829
    @fionagonza8829 Год назад

    Thank you Pedro.

  • @buihuyhung6490
    @buihuyhung6490 3 года назад

    Great tutorial, can you a tutoral on multi step form with react-hook-form and yup

  • @MSEIN2303
    @MSEIN2303 Год назад

    The best tutorial. thanks a lot

  • @thru_and_thru
    @thru_and_thru 2 года назад

    Awesome tutorial, thanks so much!

  • @maicolfg
    @maicolfg 2 года назад

    Gracias Pedro, super bueno el tutorial, facil de entender.

  • @minhthongvo5989
    @minhthongvo5989 3 года назад +1

    Thank you very much Pedro!!!

  • @deepalakshmip5520
    @deepalakshmip5520 2 года назад

    Very clean ...Superb

  • @Marcus-09
    @Marcus-09 2 года назад

    hi Pedro, amazing video as always. I have a question: how can i validate a disabled input where the value and placeholder is defined by props? Or there is no needed?

  • @kasiakordys266
    @kasiakordys266 2 года назад

    great tutorial! Thank you a lot

  • @thyago8062
    @thyago8062 3 года назад

    Amazing! Could you make a video about masked inputs with React? Thanks!

  • @yashuapervez1533
    @yashuapervez1533 3 года назад

    great tutorial, it really helped

  • @hamzamuhammad2967
    @hamzamuhammad2967 3 года назад +1

    Love your content keep it up.

  • @jamesfreeman1530
    @jamesfreeman1530 3 года назад

    Hi Pedro, how can I pass the error response from express/mongoose to yup schema to validate email uniqueness? should I put the the error response to state and from there use the state to validate from yup schema? newbie here and kind of lost. thanks

  • @RahulKumar-qu1if
    @RahulKumar-qu1if Год назад

    Can you please tell how i get the min value from the field itself not the hard-coded in the schema

  • @AMoktar
    @AMoktar 2 года назад

    Amazing. Thanks bro

  • @hamdihawari
    @hamdihawari Год назад

    Please tell me how do I clean the values after submitting :) something like reset

  • @hienqngo
    @hienqngo 2 года назад +1

    Thanks!

  • @cryptoboy1461
    @cryptoboy1461 3 года назад +1

    Great tutorial! It would be more helpful if you used different form types.

  • @amanbansal3928
    @amanbansal3928 3 года назад +1

    i got error : Could not install from "@hookform
    esolvers\yup" as it does not contain a package.json file...please help me!!

    • @Dan_ny
      @Dan_ny 3 года назад

      npm install @hookform/resolvers

  • @anisuzzaman3723
    @anisuzzaman3723 2 года назад

    If i use react hook from need to click submit button two times otherwise not work and if i give any default value in input field without mouse cursor pointer click those input field data not take or pass.could you tell me why ????

  • @deepakratra77
    @deepakratra77 Год назад

    How to do dependent validation. example if first name is predo then only last name is mandatory ?

  • @sreekanthvadassery8288
    @sreekanthvadassery8288 2 года назад

    Superb!!

  • @benitomunga4143
    @benitomunga4143 2 года назад +1

    Getting Uncaught TypeError: path.split is not a function in react:-
    react-hook-form updated to 7.0.0 from 6.X.X and has breaking changes:
    You have to replace all ref={register} with {...register('value_name')}👍

  • @gotemperory4278
    @gotemperory4278 3 года назад +2

    I am having the same issue : Its Giving an error '' TypeError: Cannot read property 'firstName' of undefined '' , so I had to do "{...register('firstName')}" instead of ref={register}. But still says
    Also not displaying errors, even if I copy paste all of your code. It looks like errors is undefined - "Cannot read property 'firstName' of undefined"

    • @PedroTechnologies
      @PedroTechnologies  3 года назад

      THank you! The library updated after I made the video so now its outdated!

    • @husseinkizz
      @husseinkizz 3 года назад +1

      @@PedroTechnologies I have the same issue but gonna look into the documentation if that's the case but don't you consider remaking your tutorials to updates over time? Anyways thanks we love your content!

  • @caiofelixreis8970
    @caiofelixreis8970 2 года назад

    brazil é cabuloso credo 👏🏾

  • @mahendranath2504
    @mahendranath2504 2 года назад

    Thank you so much 👍💕👌🙏🤞✌

  • @Isaz63
    @Isaz63 2 года назад

    Hey Pedro, excellent series of videos on React. Thanks. Su nombre y apellidos son latinos pero su acento no, cuales su ascendencia? Gracias de nuevo!

  • @akiij
    @akiij 3 года назад

    what extension is that you're using where you get syntax definitions while typing? anyone knows?

  • @Ibrahim-ir6ft
    @Ibrahim-ir6ft 2 года назад

    Exellent video

  • @softblood1941
    @softblood1941 3 года назад +1

    very helpful !

  • @ruslanpascoal9247
    @ruslanpascoal9247 3 года назад

    muito bom pedro!

  • @DioArsya
    @DioArsya 2 года назад

    Easier to use react hook form and typescript then create an interface and attach it as generic to the useForm hook. And also Yup is very large in size

  • @MrNik0l0z
    @MrNik0l0z Год назад

    from where did ref come from? when i type it the way you do, it gives me an error

  • @mralex6543
    @mralex6543 2 года назад

    Have you tried required() for Confirm Password?

  • @CHANNELGIVEWAY
    @CHANNELGIVEWAY 3 года назад

    nice amazing thank you

  • @Davi-wv8mi
    @Davi-wv8mi 2 года назад

    Nice Pedro

  • @tagalogmovierecapspoiler
    @tagalogmovierecapspoiler 3 года назад

    you save me

  • @moisesdelarosa3843
    @moisesdelarosa3843 2 года назад

    Hello, does anybody know which color theme is he using?

  • @lesharper8751
    @lesharper8751 2 года назад

    I don't understand. Why use yup if react-hook-form has built-in validation that works fine and you don't need extra libraries loading the bundle

  • @nargizgasanova6222
    @nargizgasanova6222 2 года назад

    thanks

  • @DarkShadow00972
    @DarkShadow00972 3 года назад +2

    Nice,
    Bro where r u from buddy

  • @joaopedromonteiroperaro3237
    @joaopedromonteiroperaro3237 3 года назад

    muito bom cara!

  • @brijeshp1878
    @brijeshp1878 Год назад +1

    hello from india iam getting error like this = Cannot read properties of undefined (reading 'firstName')

    • @frontendwithsalimi
      @frontendwithsalimi Год назад

      use the useForm like this
      const { register, handleSubmit, formState:{errors} } = useForm({
      resolver: yupResolver(userSchema),
      });

  • @knuckless__
    @knuckless__ Год назад

    excellent

  • @abdelrahmanmahmoud891
    @abdelrahmanmahmoud891 3 года назад

    thanxxx

  • @johnconnor9787
    @johnconnor9787 3 года назад

    How can we validate input type="file" with yup

  • @TungPham-hn1lr
    @TungPham-hn1lr 3 года назад

    I cannot install @hookform/resolvers/yup and I saw that you crashed on it as well. How did you please import this package?

    • @lyubomirdias5465
      @lyubomirdias5465 3 года назад

      just add @ hookform / resolvers ---- than import yupResolver from "@hookform/resolvers/yup"

  • @robiparvez
    @robiparvez 3 года назад

    nice work

  • @mohamedyoussef8835
    @mohamedyoussef8835 2 года назад

    Awesome explanation... thank you ++++++++++++++++++++++++++

  • @Cmxmxmmx7
    @Cmxmxmmx7 2 года назад

    errors.firstName?.message is this typescript? Why there is a question mark after firstName? Also I tried to add min(8) characters to password field but error is not showing up for some reason.

    • @denmccormik7654
      @denmccormik7654 2 года назад

      syntax has changed a bit, also "?" - that is javascript, check the docs

  • @khanhhq2044
    @khanhhq2044 3 года назад +1

    how to get the value to change input, without onSubmit?

    • @PedroTechnologies
      @PedroTechnologies  3 года назад +1

      You can create some states and change them on the onChange property!

  • @RealEstate3D
    @RealEstate3D 3 года назад +1

    Unfortunately we have already react-hok-form v7 out.

  • @Vlad-us9xt
    @Vlad-us9xt 3 года назад +1

    great

  • @ajantica
    @ajantica 2 года назад

    I got no output, following all the steps you showed

  • @nishadsandilya6653
    @nishadsandilya6653 3 года назад

    I cannot get the errors to work, even after formState:{errors}. what to do?

    • @gaurav8113
      @gaurav8113 2 года назад

      Hi Nishad! hope your doubt got resolved. Are you a self-taught programmer?

  • @mohakmaheshwari8756
    @mohakmaheshwari8756 3 года назад +1

    Its Giving an error '' TypeError: Cannot read property 'fname' of undefined ''
    I have used fname everywhere. Checked it Twice
    Please Help !!!

    • @PedroTechnologies
      @PedroTechnologies  3 года назад

      Hey, I don't think I used a variable called fname in the tutorial! I created a property called firstName, maybe the issue is there! Let me knoow if it fixes!

    • @mohakmaheshwari8756
      @mohakmaheshwari8756 3 года назад

      @@PedroTechnologies i used fname instead of firstName..... and used it same through out the entire code ... it's still not working.... maybe its version mismatch i don't know
      And when i use ref={register} it gives me bunch of errors so i had to use {... register ('fname')}