This New React Hook Changes How You Use Forms

Поділитися
Вставка
  • Опубліковано 16 лип 2024
  • React Simplified Course: reactsimplified.com/?...
    React recently announced a new experimental hook that makes working with forms so much easier. This hook solves issues related to double submitting forms, loading states, and so much more.
    📚 Materials/References:
    React Simplified Course: reactsimplified.com/?...
    🌎 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:57 - Traditional Solution
    02:45 - useFormStatus Solution
    #ReactJS #WDS #useFormStatus

КОМЕНТАРІ • 84

  • @WebDevSimplified
    @WebDevSimplified  11 місяців тому +3

    React Simplified Course: reactsimplified.com/?Udtt6H5CE

    • @ankitshukla9257
      @ankitshukla9257 11 місяців тому

      You can also use use-form-hook

    • @mahmudaremu4907
      @mahmudaremu4907 11 місяців тому

      Please can you make a review of the exchange-router module on npm

  • @GaryMenzel
    @GaryMenzel 11 місяців тому +19

    I'll at least echo some of what has already been said. React Hook Form has a lot of additional features that this new hook wont cover - so I'll be sticking with that. While I don't consider it to be "magic" (clearly the tag now has a context associated with it), it still feels like a little bit of "sleight of hand-ish". In RHF you explicitly have to use their context component to be able to refer to the enclosing form in child components. So there is some level of "mystery" with this new React hook. I can see that it may help isolate naming conflicts but just how many places in a component containing form do you really need a "pending" state? If you are writing tightly-purposed components... maybe once in that component? So I think naming clashes are going to be rare.
    Also, as pointed out, there's not much difference in the amount of code being written and the benefits come more to those using React in a SSR environment - especially where FormData is prominent.

    • @Andy-si1pl
      @Andy-si1pl 11 місяців тому

      Yeah I instantly thought reacr-hook-form too. I guess eventually it may be redundant

  • @MrMudbill
    @MrMudbill 11 місяців тому +14

    The input ref wasn't really needed in the previous implementation anyway, since you automatically get refs for named inputs within forms in the FormEvent given in onSubmit. You can have a near-identical implementation for onSubmit by doing `const data = new FormData(e.currentTarget)`.

  • @dmytrk
    @dmytrk 11 місяців тому +5

    I'm using react-hook-form for this and it gives additional benefits, such as schema validation with various libs (Yup, Zod, etc.)

  • @caincobain9318
    @caincobain9318 11 місяців тому +2

    that's exactly how remix run are handling forms, I was surprised how no one in the comment or even you Kyle did monition it.

  • @NOTHING-en2ue
    @NOTHING-en2ue 11 місяців тому

    very great tutorial, thanks a lot ❤

  • @user-nv1os5ni1y
    @user-nv1os5ni1y 11 місяців тому

    Thanks a lot for this tutorial.

  • @joepetrillo6185
    @joepetrillo6185 11 місяців тому +33

    Does anyone have a guess on when these new hooks will be released as stable? Seems like they should have existed long ago.

    • @Dev-Siri
      @Dev-Siri 11 місяців тому +2

      Seems like it will take some more time because this is a fairly recent feature that is a complement to Server Actions (SA are still in alpha)

    • @sokoyaadedolapo5321
      @sokoyaadedolapo5321 11 місяців тому +1

      Always check their documentation

    • @sicfxmusic
      @sicfxmusic 11 місяців тому

      I don't know bro, maybe check their roadmap.

    • @joepetrillo6185
      @joepetrillo6185 11 місяців тому

      @@sicfxmusic ok bro

    • @bogdanfilimon2486
      @bogdanfilimon2486 11 місяців тому +1

      These all “new concepts” from react / vercel / nextjs team is taken from Remix. So you can just use Remix and have all the goodies stable (in general).

  • @Avarn388
    @Avarn388 11 місяців тому +1

    Nice. It was just dealing with this bug in my application so seeing this being addressed with a new hook, it’s right up my alley. Thank you.

  • @anonymous_dev9472
    @anonymous_dev9472 11 місяців тому +1

    Kyle, pls bring out a full length react course on youtube 🙏🏻

  • @magicfibre
    @magicfibre 11 місяців тому +6

    Is passing a callback to the "action" something that also comes with the new React version, or is it something that exists already?
    If it's available in the current version of React, why aren't we using it instead of onSubmit?

  • @parassharma7041
    @parassharma7041 11 місяців тому

    Thank you🎉

  • @hassanshahid9499
    @hassanshahid9499 8 місяців тому

    your course is best for React Hooks , Appriciated

  • @mma93067
    @mma93067 11 місяців тому +17

    Mantine’s useform + zod feels light years ahead tho

  • @fave1201
    @fave1201 11 місяців тому +2

    Nice video. I prefer the first method though. At times, there may be some logic to be done like show a toast and just having one loading state that's your single source of truth seems easier and more straightforward.

  • @axelramirezludewig306
    @axelramirezludewig306 11 місяців тому

    This is truly epic! The php feel

  • @hireetech
    @hireetech 11 місяців тому

    Awesome!😍

  • @ajlmusic
    @ajlmusic 11 місяців тому

    Awesome!

  • @noelethan6230
    @noelethan6230 11 місяців тому

    Great tutorial, can see react is getting a PHP feel

  • @kaas99
    @kaas99 11 місяців тому +1

    This seems pretty similar to AntD implementation of Form but, it's good to have this out of the box.

  • @YourEverydayDeveloper
    @YourEverydayDeveloper 11 місяців тому +2

    react solves problems that react has created in the first place

  • @Pedro-yq8ro
    @Pedro-yq8ro 11 місяців тому

    Hey Kyle great vid, listen how can I use env vars with vite + react?

  • @ziadx3
    @ziadx3 10 місяців тому

    i love this react hook!

  • @greybluesea
    @greybluesea 11 місяців тому

    BTW, does the 'data' of 'FormData' type has a method to allow us to set it blank right after submit?

  • @hawarhekmat1174
    @hawarhekmat1174 11 місяців тому

    why i love nextjs ❤❤❤❤

  • @williamliu796
    @williamliu796 11 місяців тому +5

    would you use this over react hook form?

    • @oscardasilva971
      @oscardasilva971 11 місяців тому

      I was wondering the same

    • @wchorski
      @wchorski 11 місяців тому +1

      it's nice for learning cutting edge, but would never use any alpha/beta in a production product. React Hook Form, is meant to be used in production out of the box

    • @TannerBarcelos
      @TannerBarcelos 11 місяців тому +2

      Like William said, in prod I’d stick to RHF, but once this goes stable, I’d be more inclined to use this as it’s built in and requires less package overhead in my bundles.

  • @helleye311
    @helleye311 11 місяців тому +2

    if only this wasn't formdata I'd be excited. But I really don't like working with that. I mean sure it's native and it technically makes sense, but json is just so much nicer most of the time. Only time I use FormData is with file upload, and I always hate every minute of it.

  • @govinda399
    @govinda399 11 місяців тому

    thanks guruji :)

  • @bikbokken6040
    @bikbokken6040 11 місяців тому

    When will your NextJS course be released on your course platform? :D

  • @TannerBarcelos
    @TannerBarcelos 11 місяців тому

    Why this wasn’t the behavior from day 1, idk. But this is a beautiful addition.

  • @abhinavtariyal6099
    @abhinavtariyal6099 11 місяців тому

    What about useNavigation hook? How is it different from this hook?

  • @user-cy8mh5sc4n
    @user-cy8mh5sc4n 11 місяців тому +1

    The only channel whose speed I'm slowing down.

    • @greybluesea
      @greybluesea 11 місяців тому

      same here, speed 0.75 for Kyle

  • @tak68tak
    @tak68tak 11 місяців тому

    would this affect Next.js Server Action?

  • @LaravelScreencast
    @LaravelScreencast 10 місяців тому

    I feel using state is easier, and creating a custom form component😀!

  • @luisfrocha1
    @luisfrocha1 11 місяців тому

    This is pretty much how useFetch works on Nuxt 3, except it doesn't require tying specifically to a form.

  • @developer_bola
    @developer_bola 11 місяців тому

    Hi Kyle!
    I need crud app with json server lesssons!
    Please tech it and upload lesson

  • @pieter5466
    @pieter5466 11 місяців тому +1

    The first minute of this video reminds me of how important consistent dog-fooding of your own [company's] application is.
    You can't just develop on your local machine, and under/for your own circumstances, technical and other.
    You must incorporate a realistic range of devices, network/speed ranges, screen sizes, etc. into your dev iterations, AND frequently use your app out in the wld.

  • @chesterxp508
    @chesterxp508 9 місяців тому

    GoodJob!

  • @simbarashemaunga5575
    @simbarashemaunga5575 11 місяців тому

    Neat, but I will stick to disabling the button though

  • @gendumaladi9448
    @gendumaladi9448 11 місяців тому

    Still too many line codes. If It was related tô the structure of the like a paramater telling to "wait" the onclick function to happen.

  • @XboxArqain
    @XboxArqain 11 місяців тому

    Use react-hook-forms is the best

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

    isnt this even more complicated than the original isLoading

  • @salixar
    @salixar 11 місяців тому +9

    geez React gets overloaded with hooks that are really just workarounds for basic stuff. Instead of clean code we get a bunch of functions that have some "magic" going on under the hood. Maaan as I get older, I tend to dislike React very much.

    • @Shebu
      @Shebu 11 місяців тому +1

      Same

    • @YourEverydayDeveloper
      @YourEverydayDeveloper 11 місяців тому

      thats exactly what happens

    • @dixztube
      @dixztube 11 місяців тому

      I agree. I’m not doing my next project in react.

  • @raistlinmajere2257
    @raistlinmajere2257 11 місяців тому

    Why don't you have any angular tutorials?

  • @i-am-the-slime
    @i-am-the-slime 11 місяців тому

    This can't happen when using RemoteData in PureScript

  • @richardvsiansky6950
    @richardvsiansky6950 11 місяців тому

    Data Driven Forms is still a way to go for me. This is really limited. :/

  • @firedforfighting
    @firedforfighting 11 місяців тому

    Personally I feel this is just unecessary, maybe for really complex multistep forms like a visa application software I can understand but to me there is no way that your initial solution or a oneline debounce function is more complicated than implementing all of this especially compared to your complaints being "an extra loading variable??, difficult getting names correctly??" like what?, I'm happy for the vid though

  • @TM_LBenson
    @TM_LBenson 11 місяців тому +1

    I always turned my submit button into a spinner until I get a reply from the api

  • @Marcosmapf
    @Marcosmapf 11 місяців тому

    4:20 lost me on creating a new and unecessary abstraction just to provide context to the tool, doesn't feel like a good syntax

  • @lucascorey3475
    @lucascorey3475 11 місяців тому

    Imagine not using Svelte.

  • @muneebkarim3738
    @muneebkarim3738 11 місяців тому

    Bro I am From Pakistan, For me Your courses are too Expensive 🥺🥺

    • @dixztube
      @dixztube 11 місяців тому

      What would be a good usd cost for Pakistan viewers. Impressive you know English.

    • @usmanabdurehman97
      @usmanabdurehman97 11 місяців тому

      You don't need to buy anything. There is enough free material present on the internet to learn from. I am a self taught developer and learnt everything for free.

  • @DanelonNicolas
    @DanelonNicolas 11 місяців тому

    I wasn't subscribed... sorry bro, love your channel

  • @evgeniik_
    @evgeniik_ 11 місяців тому

    I am so far away.

  • @wishmeheaven
    @wishmeheaven 10 місяців тому +1

    1. I'll pretend that I managed to follow everything you said.
    2. It is not the first time that you are uploading content of hooks with an experimental status.
    And what if the experiment will fail..?
    I find this urgency for being the first one talking about it, at least......
    Questionable.

  • @shamaeelahmed3561
    @shamaeelahmed3561 11 місяців тому

    I just started react and i don't know what projects to make ..... can anyone help me out

  • @mdmofazzalhossain77
    @mdmofazzalhossain77 11 місяців тому

    not that much helpful. Give us the best way of handling form data without pre rendering

  • @thesunabsolute
    @thesunabsolute 11 місяців тому

    Meh, the old way is easier.

  • @gregupton6351
    @gregupton6351 11 місяців тому

    You should have started the video by saying this is an experimental hook! 🙄

  • @DannonDARKO
    @DannonDARKO 11 місяців тому +1

    Can we finally stop using todo stuff for react tutorials?