Multistep Form Custom Hook With React And TypeScript

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 มิ.ย. 2024
  • Multistep forms are a really common problem you need to solve in React, but there are no good ways to make it expandable to multiple forms. That is why I created this tutorial. It covers how to create a reusable React hook that can convert any existing set of forms into a multistep form.
    📚 Materials/References:
    GitHub Code: github.com/WebDevSimplified/r...
    JavaScript Only Multistep Form: • Can I Create This Comp...
    🌎 Find Me Here:
    My Blog: blog.webdevsimplified.com
    My Courses: courses.webdevsimplified.com
    Patreon: / webdevsimplified
    Twitter: / devsimplified
    Discord: / discord
    GitHub: github.com/WebDevSimplified
    CodePen: codepen.io/WebDevSimplified
    ⏱️ Timestamps:
    00:00 - Introduction
    00:25 - Demo
    01:05 - Setup
    02:12 - useMultistepForm Custom Hook
    05:50 - Form JSX/CSS
    13:00 - Form Steps JSX/CSS
    17:50 - Form Validation
    19:12 - Adding Form State
    27:00 - Handling Form Submission
    #React #WDS #MultistepForm

ความคิดเห็น • 149

  • @anand_dudi
    @anand_dudi 7 วันที่ผ่านมา

    We need more this type of tutorial to solve problems in real world application. thanks kyle

  • @PrincessStache
    @PrincessStache ปีที่แล้ว +5

    Thank you so much! Typescript tutorials are so needed. I really appreciate how you go through each step and keep going back to get the needed functionality.

  • @WatchMeLearnIt
    @WatchMeLearnIt ปีที่แล้ว +8

    Great video! Would LOVE to see a part 2 of this where you implement some kind of fetch request like you talked about at the end!

  • @oxynetz
    @oxynetz ปีที่แล้ว +3

    Enjoyed this format quick fast under 30mins, packed with useful tips and content. Well worth it. Thanks man

  • @SeanCassiere
    @SeanCassiere ปีที่แล้ว +68

    The fact that you are making React tutorials using Vite and Typescript is mega awesome 👍🏼👍🏼👍🏼. Big up to you man.

    • @arshiagholami7611
      @arshiagholami7611 3 หลายเดือนก่อน

      nothing beats good ol' JS. typescript is for the weaks (writing this comment while waiting for intellisense finish loading)

  • @niklassoderberg2168
    @niklassoderberg2168 ปีที่แล้ว +6

    This one was hard, but im learning typeScript so.. One of your best videos and I watch close to all of them!

  • @olexandrperlov6426
    @olexandrperlov6426 ปีที่แล้ว

    this type of multi step form is so clean and ease that I can't be happier and I will definitely use it in my project. Thank you so much

  • @EvertJunior
    @EvertJunior ปีที่แล้ว +1

    Great video. I usually work with a react-hook-form library and this video gave me some insights on how it probably work under the hood.

  • @FalioV
    @FalioV ปีที่แล้ว +1

    Awesome tutorial dude! I dont know why took me so long, but now I'm subscribed!

  • @mountaingoatgaminggg9395
    @mountaingoatgaminggg9395 ปีที่แล้ว

    Loved this tutorial, used a lot of the concepts here in my irl project I am working on, now just gotta learn how to intergrate a signature pad and how to save that and Im golden! Good Stuff

  • @chinmoykr
    @chinmoykr ปีที่แล้ว +52

    When vite ask you for project name type "." then it will create your project in current directory. no need to move your files

    • @nabinsaud4688
      @nabinsaud4688 ปีที่แล้ว +4

      He know bro .but he want to make beginner friendly

    • @chinmoykr
      @chinmoykr ปีที่แล้ว

      Ohh nice.. Maybe it will help someone.. not him but someone...

    • @nabinsaud4688
      @nabinsaud4688 ปีที่แล้ว

      @@chinmoykr yes Lets meet bro show your github link

    • @TheZayzoo
      @TheZayzoo ปีที่แล้ว +2

      I didn't know, thanks for the free information.

    • @guestofallah7661
      @guestofallah7661 ปีที่แล้ว +1

      @@nabinsaud4688 so the comment need some expert to understand it ?

  • @kunfun1916
    @kunfun1916 ปีที่แล้ว +1

    Nice tutorial! I rewrote this in solid-js. Learn a lot.

  • @kelvink96
    @kelvink96 2 หลายเดือนก่อน +1

    I have been looking for such a tutorial. Thanks so much for this 👍👍

  • @clarkdnro
    @clarkdnro ปีที่แล้ว

    What a beautiful Form you created. Wow, very beautiful

  • @philipjamesajagabos2519
    @philipjamesajagabos2519 ปีที่แล้ว

    A second video from you that gives me good head-ups to understanding react. Thanks for the good content.

  • @kingsleyovo8889
    @kingsleyovo8889 ปีที่แล้ว +7

    Nice videos as always I have found that kyle slowly transform the language from js to ts…. Ts should be the greatest adapter for learning Java and js

  • @Alex-uc1mp
    @Alex-uc1mp ปีที่แล้ว +9

    Danke! Wow 😲 this is exactly what I was looking for today. Destiny 😄

    • @coderyan
      @coderyan ปีที่แล้ว +1

      Love it when a tutorial just comes out at the right time to solve a problem

    • @WebDevSimplified
      @WebDevSimplified  ปีที่แล้ว +1

      Glad I could help!

  • @TheFirstUserHandle
    @TheFirstUserHandle 6 หลายเดือนก่อน

    Great tutorial. Love your stuff. This helped me out significantly.

  • @bravo1oh1
    @bravo1oh1 ปีที่แล้ว +2

    I literally am needing this right now

  • @martinkoller3595
    @martinkoller3595 ปีที่แล้ว +2

    Great tutorial! I Appreaciate that a lot.

  • @muhayminkhan7063
    @muhayminkhan7063 ปีที่แล้ว +2

    Today i've learned a best way to do some things thanks to you
    (1) React-simple-search-filter (form your other video)
    (2) Multistep-form-React-Typescript (This is the Brilliant way I guess )
    ❤❤

  • @elelan
    @elelan ปีที่แล้ว +1

    This is what I've been searching everyday for past few months...! React with Typescript and Vite

  • @marvelBoy1909
    @marvelBoy1909 ปีที่แล้ว +4

    Need more of these react typesrcipt vite projects 🔥 👍

  • @gyros9162
    @gyros9162 ปีที่แล้ว

    Thank you so much! I've used your approach in my student project and mentioned you in github )

  • @EricShans
    @EricShans ปีที่แล้ว +1

    Great video, took a bit but I fully understand it !

  • @developer_hadi
    @developer_hadi ปีที่แล้ว +5

    Bro thank you so much this is very simple and easy, please keep sharing things like this in react and typescript because it really makes my life easier as a beginner in react

    • @coderyan
      @coderyan ปีที่แล้ว +1

      Good luck with your journey with learning React!

    • @developer_hadi
      @developer_hadi ปีที่แล้ว

      @@coderyan thanks

  • @fipabrate
    @fipabrate ปีที่แล้ว

    This helped me a lot. Thank you!

  • @darkNovaskar
    @darkNovaskar 9 หลายเดือนก่อน

    Gotta say thank you for having a clear easy to understand voice. All these TH-camrs got thick azz accents and this coding shit is hard enough 😤

  • @baolee4622
    @baolee4622 7 หลายเดือนก่อน

    Amazing explanation!

  • @kanishka5948
    @kanishka5948 ปีที่แล้ว +1

    Just what I needed 😌

  • @focusroom_
    @focusroom_ ปีที่แล้ว

    Amazing as always

  • @simplyabdou8425
    @simplyabdou8425 ปีที่แล้ว +1

    great video Kyle

  • @piyushaggarwal5207
    @piyushaggarwal5207 ปีที่แล้ว

    Loved the tutorial

  • @paulthomas1052
    @paulthomas1052 ปีที่แล้ว +1

    Great video. Thanks.

  • @blogpegaaki
    @blogpegaaki ปีที่แล้ว +1

    Amazing friend!

  • @user-zs8kg2nm4w
    @user-zs8kg2nm4w ปีที่แล้ว

    Thank you very much it helped me a lot☺

  • @kinamartinez
    @kinamartinez 8 หลายเดือนก่อน

    Thank you very much, its an amazing video, very useful

  • @yevhenlysenko7444
    @yevhenlysenko7444 ปีที่แล้ว +1

    More similar lessons with TS are needed)

  • @milendonchev737
    @milendonchev737 ปีที่แล้ว +1

    Great video as always my friend! Quick tip (you probably know, but anyway) - When you create a Vite app, which you want to be in your CWD, when it asks you for name of project, just type a dot (".") and it will create the project in there. :)

    • @coderyan
      @coderyan ปีที่แล้ว

      Nice tip! Something I can use in future projects.. pretty new to Vite

  • @UnderstandingCode
    @UnderstandingCode ปีที่แล้ว

    1m subs congrats

  • @beinerthchitivamachado9892
    @beinerthchitivamachado9892 ปีที่แล้ว

    Kyle, you're the GOAT!

  • @kartik7775
    @kartik7775 ปีที่แล้ว +1

    No matter how great a job I land in future, I'll always be grateful for your lessons and will dedicate my success to you. 🙌

    • @whatsapp176
      @whatsapp176 ปีที่แล้ว

      Helpline 📲📩⬆️
      Questions can come in⬆️

  • @pmioduszewski
    @pmioduszewski ปีที่แล้ว +1

    One day this video will save your day

  • @benny-shen
    @benny-shen ปีที่แล้ว +1

    Great content

  • @Anushkai1
    @Anushkai1 4 หลายเดือนก่อน

    It great. Thank you very much

  • @khurshedaalam7478
    @khurshedaalam7478 5 หลายเดือนก่อน

    Awesome bro love from india

  • @Mammodreoci
    @Mammodreoci 20 วันที่ผ่านมา

    Great video

  • @wudao88
    @wudao88 10 หลายเดือนก่อน

    Thanks King

  • @AMoktar
    @AMoktar ปีที่แล้ว

    Amazing thanks 🙏

  • @gray_hat
    @gray_hat ปีที่แล้ว +10

    There is also a ReactPropsWithChildren interface your props could extend. That automatically adds a children field to your props

    • @piyushaggarwal5207
      @piyushaggarwal5207 ปีที่แล้ว +1

      It is PropsWithChildren actually. Thanks!

    • @piyushaggarwal5207
      @piyushaggarwal5207 ปีที่แล้ว

      There is one problem though what if we want the children to be required. It is optional in the type you mentioned.

    • @gray_hat
      @gray_hat ปีที่แล้ว +2

      The type for children is ReactNode
      If children is required by your usecase then you can potentially add `children: ReactNode` without using PropsWithChildren.
      Although for such use cases you probably have a specific type you might wanna use for children and not the generic one. So you can do that too.

    • @uome2k7
      @uome2k7 2 หลายเดือนก่อน

      ​@@piyushaggarwal5207 you can use the Require util type to set fields of a type to be required.

  • @GMPGIRI
    @GMPGIRI ปีที่แล้ว

    Please more React + Typescript projects. 🙏

  • @michaeltrembovler8301
    @michaeltrembovler8301 6 หลายเดือนก่อน

    Grate. Thank you !!!

  • @oleksiihmyrko7969
    @oleksiihmyrko7969 ปีที่แล้ว +1

    Thanks so heplful!

  • @joaoarthurbandeira
    @joaoarthurbandeira 8 หลายเดือนก่อน

    Hey Kyle,
    - How can i implement this in combination with Zod, for example?
    - Also, how could i modify the code if i want to use Redux toolkit for this?
    - And how can i implement the 'goTo' part so i can quickly jump to a specific part of the form?
    - Finallly, Will the state be preserved even if the user refreshes the page or - in a system - log out and log in again?
    Lots of questions haha, but thanks anyway!

  • @abdullahrafique2883
    @abdullahrafique2883 ปีที่แล้ว

    hey thanks so much for this wonderful tutorial. what if I wanna write the custom validation to any of the individual form field?

  • @shivamrathore8291
    @shivamrathore8291 ปีที่แล้ว

    Hey,
    thanks for the video.
    (apart from video's topic) I am in a little bit of confusion in CSS
    CONFUSION : can we edit/modify the input box blinking cursor
    I want to change the input box cursor blinking animation style from blink to expand (like VS code)
    is this possible? if yes then please make a video or at least tell me how can I achieve this??,
    if not then why??

  • @artemryabykh
    @artemryabykh 2 หลายเดือนก่อน

    Thank you for the guide! Could you please advise if we can use custom validation with this form?

  • @yahiachougui6074
    @yahiachougui6074 ปีที่แล้ว +1

    Great video, is there a way to pass the fnction next() or a function goTo() to one of the step elements? that way when you have like a summary step where you review all the information you can go back to a particular step and change the information in it?

    • @pofiabel9526
      @pofiabel9526 ปีที่แล้ว

      Hi I am currently having same challenge. Can someone anyone please respond to this question. Thanks in anticipation.

  • @gopinathkrm58
    @gopinathkrm58 ปีที่แล้ว

    thanks and great, and I have a doubt from ur Spotify clone video, it is playing only for 30 seconds but how to play it fully. I used audio_preview_url from response data.

  • @Alyaman_Accounting_System
    @Alyaman_Accounting_System ปีที่แล้ว

    awesome thank very match

  • @plamenpetkov746
    @plamenpetkov746 ปีที่แล้ว +1

    What's the alternative for steps: ReactElement[] from the custom hook in ReactJS, cuz I don't know TypeScript?

  • @kathirmldata7411
    @kathirmldata7411 ปีที่แล้ว +2

    Happy Aayutha Pooja 🥰

  • @penguinthesolver1405
    @penguinthesolver1405 10 หลายเดือนก่อน

    Hello! Thanks for tip, but how to implement custom validation for every form in this scheme?

  • @eliamzg
    @eliamzg ปีที่แล้ว +1

    This would have been great 2 years ago before I had to come up with my own as a junior react dev

  • @shahramhz1444
    @shahramhz1444 10 หลายเดือนก่อน

    Tnk excellent ❤❤

  • @Mutoforma
    @Mutoforma ปีที่แล้ว

    Awesome!
    Around 26:30, how were you highlighting both instances of 'email' in the value/onChange props?

    • @ongangminh6627
      @ongangminh6627 ปีที่แล้ว

      Ctrl + D, bro

    • @whatsapp176
      @whatsapp176 ปีที่แล้ว

      Helpline 📲📩⬆️
      Questions can come in⬆️

  • @justpeace7852
    @justpeace7852 ปีที่แล้ว +3

    Лайк не глядя

  • @juanita8149
    @juanita8149 ปีที่แล้ว

    Any sources on how to accomplish this with Select? Specifically, when the Select is in a separate component?

  • @turbulantarchitect5286
    @turbulantarchitect5286 ปีที่แล้ว +1

    Hi Web Dev Simplified, can you please make a series on how to create reusable form component, input components, error/validation handling with Hooks. Thanks

    • @whatsapp176
      @whatsapp176 ปีที่แล้ว

      Helpline 📲📩⬆️
      Questions can come in⬆️

  • @zakidzz
    @zakidzz ปีที่แล้ว +1

    please make a course on typescript bigginer and advanced

  • @zixuanchen8898
    @zixuanchen8898 ปีที่แล้ว +1

    Very great tutorial, I want to ask about how to let the code auto format when on save?

    • @coderyan
      @coderyan ปีที่แล้ว

      In most code editors, you can access the "preference" tab, and then you can search for "on save" -- often, you'll see an option to enable format on save

    • @zixuanchen8898
      @zixuanchen8898 ปีที่แล้ว

      @@coderyan Thank you!

  • @amitakolkar2389
    @amitakolkar2389 ปีที่แล้ว +1

    This is a great way to create a multistep form. Thanks for sharing.
    How can we handle a large forms with different sections?
    Here as well you have maintained one single state at parents and its updating whole object every onchange event. {...pre, ... currentField}
    Having soo many inputs and those are dependent on each other. As we are passing a object down it rerenders all children components. We can pass a primitive data to children and use useCallback hook at the top. But still it doesn't seems like best way. Can you please create a video on that about how to handle a large forms with best performance.

    • @whatsapp176
      @whatsapp176 ปีที่แล้ว

      Helpline 📲📩⬆️
      Questions can come in⬆️

  • @carolinatavares1843
    @carolinatavares1843 ปีที่แล้ว

    do you think this project could benefic of using useReducer instead of useState?

  • @nandoomb
    @nandoomb ปีที่แล้ว +1

    Great, but... If you put your buttons (next, back,...) inside your "Step Component". How could you do that?

  • @jokrdev3517
    @jokrdev3517 10 หลายเดือนก่อน

    thank you for this great tutorial sir, please why can i persist data for checkbox ?

  • @deepikarao2593
    @deepikarao2593 6 วันที่ผ่านมา

    How would you use formik with this stepper function for validations

  • @sandeepsinghmehra3237
    @sandeepsinghmehra3237 ปีที่แล้ว

    How to add routing and change components with routing within multistep in react-router v6?

  • @karis7539
    @karis7539 ปีที่แล้ว +1

    Would be so much cooler with carousel animation

  • @Lichkuroro
    @Lichkuroro ปีที่แล้ว

    Hey Chief!! , im not using, typescript and when i send the steps from app to useMultiStepHook, it is received as an array of objects, so console.log(steps) reads its info, but console.log(steps.lenght) is undefined..
    heres what inside steps [ {
    '$$typeof': Symbol(react.element),
    type: 'div',
    key: null,
    ref: null,
    props: { children: 'One' },
    _owner: null,
    _store: {}}, {... }, {...} ]
    but steps.lenght is undefined.. thnx in advance

  • @eddyelamin9015
    @eddyelamin9015 ปีที่แล้ว

    Hi Kyle can you help me with this mongoose error : Task validation error path content is required
    Im on version 6.6.5 btw

  • @kanishkkumar535
    @kanishkkumar535 10 หลายเดือนก่อน

    you are fast AF

  • @Distortie
    @Distortie ปีที่แล้ว

    Anyone have issue with pages 2 and 3 not keeping their data when going back and forwards through the buttons? the data object gets updated.. just not the data staying inside the input fields

  • @szymonoleszek2086
    @szymonoleszek2086 ปีที่แล้ว +1

    Why did you switch to vite? Is CRA dead now? How are the things look like with setting up the react projects now?

    • @SeanCassiere
      @SeanCassiere ปีที่แล้ว +2

      CRA isn't quite dead yet, but you really should be using Vite instead.
      Since Vite uses ESBuild the dev experience is much faster. Also, it doesn't give you foot guns like polyfilling node_modules into the client which could create some unintentional mess ups.

  • @nirajgurung8348
    @nirajgurung8348 ปีที่แล้ว

    How can we add frontend validation in this form?

  • @awekeningbro1207
    @awekeningbro1207 ปีที่แล้ว

    Is there a reason why is the form data state and the form data handler not put in the hook?

    • @SeanCassiere
      @SeanCassiere ปีที่แล้ว

      That is because the hook is being used purely for managing the logic of the multi-step process. This would then allow for multiple independent multi-steps forms sets to be implemented without having to duplicate and manage that logic.
      Plus the form state and submit stuff could change quite abit depending on the type of info being collected and is better left to the dev to handle that individually.

  • @avtar618
    @avtar618 ปีที่แล้ว

    hey bro can yoy make course on backend? your way of teaching is awsome i'm starting css today by the time i will end frontend if you has backend course it will be awsome

  • @MightyKingKala
    @MightyKingKala ปีที่แล้ว

    I love you

  • @bigguns845
    @bigguns845 ปีที่แล้ว

    How can i build a booking appointment for a doctor office

  • @anaordonez7906
    @anaordonez7906 7 หลายเดือนก่อน

    what does the & mean when he declared the UserFormProps???
    type UserFormProps = UserData & {
    updateFields: (fields: Partial) => void;
    }

  • @mustak_085
    @mustak_085 11 หลายเดือนก่อน

  • @leonitshaqiri9671
    @leonitshaqiri9671 หลายเดือนก่อน

    How to achieve this results with Formik and Yup validation

  • @illuminatiOrden
    @illuminatiOrden 8 หลายเดือนก่อน

    How to use that goTo Function ??

  • @amirulidzham
    @amirulidzham ปีที่แล้ว

    Angular not supporting vite yet?

  • @kmylodarkstar2253
    @kmylodarkstar2253 5 หลายเดือนก่อน

    nice video thanks!
    type FormData = typeof INITIAL_DATA; best choice?

  • @jasonzhang4632
    @jasonzhang4632 ปีที่แล้ว

    neat

  • @DilanDog
    @DilanDog ปีที่แล้ว

    What about this… [steps,setSteps]=useState([…] )and just loop over and Set counter :D

  • @deatho0ne587
    @deatho0ne587 ปีที่แล้ว +1

    At 25:42 you have a lot of repeated code that works, but is there a better way in React?
    I have been working in Angular for quite some time and generally make arrays of objects that make repeated stuff. Something like [{field: 'localZip', maxLength: 5, type: 'number'}, {field: 'city', maxLength: 30, type: 'text'}]. That array would make all the HTML elements and the labels would use the field to make something like "Local Zip" and "City".

    • @Zikakoo
      @Zikakoo ปีที่แล้ว

      Yes, a cleaner way to do it is to create an array of objects from the interface keys and fill in the needed information per input (label, required, value etc whatever is needed). Passing the values as an object you can access the inputs own value with the bracket notation. Then loop through that array of objects to create the inputs needed.

  • @waleedsharif618
    @waleedsharif618 ปีที่แล้ว

    I learned two things: FormWrapperProps and that partial. Question: formwrapperprops has ”children” as props, what it is ?

  • @markalot9728
    @markalot9728 ปีที่แล้ว

    how i connect INITIAL_DATA to a mongodb?

  • @mohamedmaher2981
    @mohamedmaher2981 หลายเดือนก่อน

    i can't use this with react-form-hook i