Forms in React with Formik

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

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

  • @83garimasharma
    @83garimasharma 4 года назад +1

    I am a novice in Formik, your detailed video on how things work really gave me a good starting point. Thanks.

    • @leighhalliday
      @leighhalliday  4 года назад

      Excellent!! Glad it could help :) Thanks for saying hi!

  • @ridl27
    @ridl27 5 лет назад +16

    Hey, You have really decent tutorials on this channel! I am pretty sure that you will have much more subs in the near future! Just keep going :)

    • @leighhalliday
      @leighhalliday  5 лет назад +4

      Thank you! I would have taken half-decent, but fully decent is great news :D

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

    Thank you for this awesome video... It's my first time learning Formik and you explained it clearly :)

  • @AnthonyInSanDiego
    @AnthonyInSanDiego 4 года назад

    You're my favorite react tutorial channel! thanks a lot

    • @leighhalliday
      @leighhalliday  4 года назад

      Thank you Anthony!! :) Glad you're enjoying the content!

  • @harikamath7533
    @harikamath7533 5 лет назад

    Wonderful tutorial, crisp pace, clearly understanding the contents, well presented with clear explanations. Glad to have come across this video. Keep up the good work!

    • @leighhalliday
      @leighhalliday  5 лет назад +1

      Thank you, Hari! I plan to keep producing tutorials... stay tuned!

    • @harikamath7533
      @harikamath7533 5 лет назад

      @@leighhalliday Hey...Can you do tutorials on react native as well if you can... Will be really helpful for many...🥴😁

  • @RasenganV99
    @RasenganV99 4 года назад

    Thanks for the video! This seriously helped me out since I was stumped on this topic despite trying to google around for particular documentation for a few hours. Love the verbal detail!

    • @leighhalliday
      @leighhalliday  4 года назад +1

      Nice!! That makes me feel good :D Glad you enjoyed it!

  • @BHFJohnny
    @BHFJohnny 5 лет назад +2

    Ohoho. Thank you, Leigh! This is exactly what I need for my project.
    Last time, I did all of that basically all by myself, because I was repairing old app that used Polymer 0.8, which does not use npm.
    I wouldn't say it takes so much code to write this. But with 6 fields, validations, blurring, touching, submitting, resetting... It does.

    • @leighhalliday
      @leighhalliday  5 лет назад +2

      Yea for sure... it seems easy, then you're 300 lines into your form thinking shoot, I should have used Formik.

  • @cibellemontor
    @cibellemontor 5 лет назад

    Great tutorial! Thank you Leigh , the way that you went over made it so easy to understand!

    • @leighhalliday
      @leighhalliday  5 лет назад +1

      Nice! Thank you, Cibelle! Would love to have you subscribe. Any topics you'd like to see covered?

    • @cibellemontor
      @cibellemontor 5 лет назад

      @@leighhalliday React Hooks would de nice!

  • @muhammadsheharyar999
    @muhammadsheharyar999 4 года назад

    Thank you so much for helping me out with the formic. I am a complete beginner to react and I understood everything. You are an awesome teacher.

    • @leighhalliday
      @leighhalliday  4 года назад

      Nice! I'm glad I was able to help :) Thanks for watching and saying hi!

  • @shane_marotical
    @shane_marotical 4 года назад

    Thanks alot for the detailed explanation .It has helped me immensely in my current project:) keep it up

    • @leighhalliday
      @leighhalliday  4 года назад +1

      Thanks Shane!! I won't let you down!

  • @majedjendi3781
    @majedjendi3781 5 лет назад

    Thank you for the very clear and step by step explanation!

    • @leighhalliday
      @leighhalliday  5 лет назад

      Thank you Majed! Glad you enjoyed it. Formik is pretty cool eh?

  • @Justin_Min_001
    @Justin_Min_001 4 года назад

    Super neat and straightforward tutorial on Formik. It does help! Thank you Leigh.
    Would be great if you could make a video on image-uploading using Formik and Yup.

    • @leighhalliday
      @leighhalliday  4 года назад +1

      Hey Justin! Great idea about image uploading... maybe a "straight to S3 upload" as well would be cool. I've added it to my list!

  • @pjayo
    @pjayo 5 лет назад +1

    a great video thanks Leigh. Will be trying it out ASAP

  • @SzTz100
    @SzTz100 5 лет назад

    Nice work there, very clear explanation.

  • @reporter5534
    @reporter5534 5 лет назад

    Thank you!
    You saved from desperation over forms and moving forward in my project!
    Great presentation too!

    • @leighhalliday
      @leighhalliday  5 лет назад

      Thank you Reporter553!! Glad you enjoyed it :)

  • @nathandaniel1877
    @nathandaniel1877 5 лет назад

    Thank you for sharing your knowledge in a very clear manner!

    • @leighhalliday
      @leighhalliday  5 лет назад

      Thank you for replying in a very kind manner :D

  • @hugot8226
    @hugot8226 5 лет назад

    Great tutorial about Formik, thanks dude you nailed it ! Liked and subscribed !

  • @shahotoofani9913
    @shahotoofani9913 5 лет назад

    Really really appreciate, clear explanations, please consider complex use cases, thanks again

    • @leighhalliday
      @leighhalliday  5 лет назад +1

      Hey Shaho! I've heard from a couple people to cover forms with plurals... like an array of field combos for adding multiples of something, multi-step forms, and conditionally rendering/validating fields (Canada == Postal Code, USA == Zip Code). All in the works!

  • @firebird77
    @firebird77 4 года назад

    Thank you! This got me going quickly on a huge dynamic form!

    • @leighhalliday
      @leighhalliday  4 года назад

      Nice! Glad the video could help, thanks for saying hi Matthew!

  • @ajaykumar-nx7kb
    @ajaykumar-nx7kb 4 года назад

    Nice explanation about Formik and Yup, thank you. Please make a video with React Native on Formik.

    • @leighhalliday
      @leighhalliday  4 года назад

      Hey Ajay! I haven't worked much with React Native yet... I should get more into it eh? I just love the web so much :D Can deploy updates without needing blessings from Google or Apple.

  • @Arrezzz
    @Arrezzz 5 лет назад

    Such an educational video, thank you!

    • @leighhalliday
      @leighhalliday  5 лет назад +1

      Thanks Arasto, would love to have you subscribe, more videos on the way :)

  • @riclavers3743
    @riclavers3743 5 лет назад +1

    thanks for the video! I was having trouble finding a good into video on Formik until yours!

  • @silicongen
    @silicongen 4 года назад

    amazing video for beginners! thanks a lot.
    now I can handle forms much easier and faster.

    • @leighhalliday
      @leighhalliday  4 года назад

      Awesome!! Glad the video could help :)

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

    Good video and also i've seen that've introduced Formik that is great! But please try final-form -> react-final-form, we're using it in production and it's just ideal form library!

  • @JustinMorgan
    @JustinMorgan 5 лет назад

    Good examples on Formik!! Cheers!

  • @AsadKhan-ok2wj
    @AsadKhan-ok2wj 5 лет назад

    You have done great Job Leigh, this is really helped, awesome, keep it up

  • @sonphan8162
    @sonphan8162 5 лет назад

    Very clear explanations. Thanks

  • @nagwan_sami
    @nagwan_sami 5 лет назад

    thank u
    i was having trouble finding a good kick start in Formik and Yup till i find your video

    • @leighhalliday
      @leighhalliday  5 лет назад

      Sweet! Thanks for watching, Nagwan! Glad it was able to help :)

  • @dhirendrasing
    @dhirendrasing 4 года назад

    Simple and Informatics . tutorial should be like dis. appreciated the way you represent your code. actually i like your almost all topics....

    • @leighhalliday
      @leighhalliday  4 года назад +1

      Thank you very much, Dhirendra! Glad you enjoy the vids :)

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

    Great tutorial. Appreciate it.

  • @satyajeetkumarjha1482
    @satyajeetkumarjha1482 5 лет назад

    it really helped me to get started with formik .u r a gem.

    • @leighhalliday
      @leighhalliday  5 лет назад +1

      Haha thanks ... Happy to be a gem! Especially since I work with Ruby.

  • @damonwu9658
    @damonwu9658 5 лет назад +2

    Thanks for sharing and alternative error message display could be using which is Formik built-in API,

    • @leighhalliday
      @leighhalliday  5 лет назад +1

      Beautiful! Didn't even know that existed :D

  • @L4poker
    @L4poker 4 года назад

    Your explanations were clear, methodical, and easy to follow thanks for that!
    As somebody that’s new to HTML/JS would you suggest that I learn the old school method of creating forms before starting to use Formik? Manually learning how to handle all these features like error validation, etc.?
    Or is it generally accepted to just start using all these frameworks to offload the learning curve?
    Thanks again.

    • @leighhalliday
      @leighhalliday  4 года назад

      Hey there! Thank you :) Honestly, use whatever works for you... if you can ship stuff quickly and learn the details later, go for it. If you prefer to learn the details first, go for it!

  • @woldemarkiev
    @woldemarkiev 4 года назад

    Thank you for such a great explanation - that really helped me t grasp this topic

  • @MrChrisk8er
    @MrChrisk8er 5 лет назад

    Thanks dude... you save my day... keep it.

  • @carloseustaquiooficial
    @carloseustaquiooficial 5 лет назад

    best formik tutorial i've found! thank you so much!

  • @dominikseljan3043
    @dominikseljan3043 5 лет назад

    Great video Leigh! Here's a suggestion for a video: making forms with nested repeating fields. For example, adding multiple addresses for users. So how to do this with formik and validation of each item in the array using Yup.

    • @leighhalliday
      @leighhalliday  5 лет назад +1

      Great idea Dominik! I was also thinking about doing something about conditional validation... Canadian Postal Code vs US Zip Code depending on the country you choose.

    • @dominikseljan3043
      @dominikseljan3043 5 лет назад

      @@leighhalliday That would be very useful as well!

  • @am6utoi97
    @am6utoi97 5 лет назад

    Great explanation, thank you for the tutorial!

  • @yaroslavoz
    @yaroslavoz 4 года назад

    Great! Thanks a lot dude! Used your tutorial in project. Works perfect with next.js

    • @leighhalliday
      @leighhalliday  4 года назад +1

      Nice! Next.js is my go-to framework in React... love the routing and being able to quickly spin up some api backend routes.

    • @yaroslavoz
      @yaroslavoz 4 года назад

      @@leighhalliday unfortunately can't get how to make the mutation with GraphQL and Apollo server when submitting the sighnup form(((
      Could you please make a video or explain somehow this staff?

  • @irhamputra3666
    @irhamputra3666 5 лет назад

    great explanation and now I understand how to use it. Thank you so much :)

  • @albjzan
    @albjzan 5 лет назад

    Thanks, very informative

  • @Denvercoder
    @Denvercoder 5 лет назад

    WOW! This was great! Formik finally makes sense to me.

    • @leighhalliday
      @leighhalliday  5 лет назад +1

      Niiiice! That's awesome to hear! Thanks for sharing, Denver!

  • @ahache888
    @ahache888 5 лет назад

    Leigh, you're awesome! Keep going

    • @leighhalliday
      @leighhalliday  5 лет назад

      Thank you ahache888 :D Thanks for watching and leaving a comment!

  • @raboija
    @raboija 5 лет назад

    Great instructor

  • @francisbadasu2108
    @francisbadasu2108 5 лет назад

    Great stuff... keep it coming

    • @leighhalliday
      @leighhalliday  5 лет назад +1

      Thanks, Francis! More stuff on the way soon!

  • @muratasarslan2359
    @muratasarslan2359 5 лет назад +1

    Thank you Leigh. Very clear and helpful especially for beginners. Would've been great if you created a useFormik hook and use it instead of render props :)

    • @leighhalliday
      @leighhalliday  5 лет назад

      Thanks muratas!! Good idea! I actually think v2 of Formik will come with a hook, so I'll have to do a new video when that comes out!

  • @klebergermano3356
    @klebergermano3356 4 года назад

    Great tutorial,, help me a lot, tks

    • @leighhalliday
      @leighhalliday  4 года назад

      Awesome!! Glad the video could help :)

  • @Asadraza-vy1cn
    @Asadraza-vy1cn 4 года назад

    Great video .

  • @painkiller2125
    @painkiller2125 5 лет назад

    thanks for the video!!!!

    • @leighhalliday
      @leighhalliday  5 лет назад

      Hope learning about Formik was able to kill some of the pain of dealing with vanilla forms in React :D

  • @LogansRun45
    @LogansRun45 5 лет назад +1

    Thank You!

    • @leighhalliday
      @leighhalliday  5 лет назад +1

      You're welcome :D Thanks for watching, LogansRun45!

  • @soleypas
    @soleypas 5 лет назад

    Thanks man, it was useful. Subscribed ;)

  • @tech4028
    @tech4028 4 года назад

    you are so GOOD.

  • @eliotness1875
    @eliotness1875 5 лет назад

    Excellent instructor, using formik how would you separate the logic of the fetch / axios from the component?

    • @leighhalliday
      @leighhalliday  5 лет назад

      Hey Eliot! Good question. I don't think there is anything stopping you from placing this logic in another file/function, and just importing it into your component. That's probably preferred actually! Easier to test in isolation.

  • @boludokid
    @boludokid 5 лет назад

    perfect video

  • @RajSingh-sj2bp
    @RajSingh-sj2bp 5 лет назад

    Unless your needs are very basic or you are very lazy, roll your own. There is some good stuff in this library, but it has some huge gaps (form-level onChange???) and the most useful part (the validation) is actually provided by yup. I spent a couple weeks with Formik before abandoning it for a 100-line version I wrote myself that met all my requirements. React plus something like yup is all you need to implement very robust web forms.

    • @leighhalliday
      @leighhalliday  5 лет назад

      Thanks for the feedback, Raj! I personally find Formik pretty useful, but it's nice to hear your point of view!

  • @muhammadishaq38
    @muhammadishaq38 5 лет назад

    always the best thank you Sir from PAKISTAN

  • @vijaykumarreddyalavala3713
    @vijaykumarreddyalavala3713 5 лет назад

    16:36 We are already telling what clicking a submit button should do in onSubmit prop of Formik. So then why do we need to bind handleSubmit function again in Form component.
    How are Formik's onSubmit prop and Form's onSubmit prop different? Can someone please explain?

    • @leighhalliday
      @leighhalliday  5 лет назад +1

      Hey Vijaykumar! Formik has a form element embedded inside of it, but they aren't explicitly connected. To allow the form's submit event to trigger Formik's submit event, you pass the `handleSubmit` function to the `onSubmit` prop of the form. This way Formik knows when the form is being submitted. It's sort of the glue that binds them together.

  • @rausanfikri2633
    @rausanfikri2633 4 года назад

    thanks mr leigh. :)

    • @leighhalliday
      @leighhalliday  4 года назад +1

      You're welcome!! Thanks for saying hi!

  • @rvicinip
    @rvicinip 4 года назад

    Thank you

  • @jamesnguyen868
    @jamesnguyen868 4 года назад

    Hi Leigh, can you make a video for form performance improvement? Like when you use FieldArray in formik to create 1000 checkboxes. That will make the form so laggy and how to optimize that?

    • @leighhalliday
      @leighhalliday  4 года назад

      Hey James! Hehe, that's one insane form. To be honest I haven't experienced form performance issues before because I can't think of a time I have had to manage even 100s of fields at once. Could this form be split up?

    • @jamesnguyen868
      @jamesnguyen868 4 года назад

      @@leighhalliday Hi Leigh, it is an edge case, to be honest. In the form, I have a search bar for word search or for category search and it will return the search result as checkboxes that people can select. Normally it would still be around 200 options which slow down the form. I use the profiler to check what is going on and find out that whenever I click a checkbox, the form actually all will be validated or something or re-render. Hence, make the form slow down. Is there a way for me to just change the input value and not have to re-render everything? Or is it an expected behaviour of Formik?

  • @MauricioSierra
    @MauricioSierra 5 лет назад

    Hey, Thanks for sharing! can you tell us how to change the initial values ​​when you change a drop-down or something like that? Thanks!

    • @leighhalliday
      @leighhalliday  5 лет назад +1

      Hey Mauricio, are you talking about just updating the value of a field? If so, you aren't changing the initial value at this point, you're just changing the current value. You can change the form values imperatively by calling this function yourself based on another event occurring: jaredpalmer.com/formik/docs/api/formik#setfieldvalue-field-string-value-any-shouldvalidate-boolean-void

  • @raboija
    @raboija 4 года назад

    Good morning, I have been having an issue in getting Data out of Formik and Material UI inputs, the Formik onchange method despite being good at validating with Yup, but it doesnt update input data I get by console log.

  • @sathiyamoorthyr3207
    @sathiyamoorthyr3207 5 лет назад

    Nice video

  • @mauroinde
    @mauroinde 4 года назад

    Hey, Is it possible to use Yup, or any react validator for a Form. Without using Formik. I prefer managing my local state with useState.
    How can I do it?

    • @leighhalliday
      @leighhalliday  4 года назад +1

      Hey! Yea, definitely... you're definitely asking for some work, but prior to saving the state, you probably also want to run it through Yup validations and keep track of the "errors" for your form at any point... basically re-implementing what Formik takes care for you!

    • @mauroinde
      @mauroinde 4 года назад

      @@leighhalliday So Leigh, you strong recommend me to use Formik :( , so far My Form state was really good and easy with a useState, I believe that Formik is redoing what is already done, which is taking the state of the Form.
      that's why I ask if I can implement only Yup

  • @MattDuarte11
    @MattDuarte11 5 лет назад

    Good video, I am running into an issue though. I used withFormik to connect my component to formik. I’m withFormik I have a handleSubmit: (vale’s, props) => { props.getFormValues(values)} when I submit it doesn’t crash doesn’t show errors nothing. Having a callback is breaking the form. Any ideas?

    • @leighhalliday
      @leighhalliday  5 лет назад

      Hmmm, I'm not sure! Do you have a codepen you could share?

    • @MattDuarte11
      @MattDuarte11 5 лет назад

      Leigh Halliday hey figured it out. Thanks though.

  • @samael1864
    @samael1864 4 года назад

    Hi! How can I submit Formik form, using button from another functional component?

    • @leighhalliday
      @leighhalliday  4 года назад +1

      Hey there! Formik provides you with a `submitForm` function formik.org/docs/api/formik#submitform---promise that you can pass down to a child component. It'd look soooomething like this:
      {({submitForm}) => (
      submitForm()} />
      )}
      So child can call the `submit` function which will trigger form submission.

  • @samiles171094
    @samiles171094 4 года назад

    I want to trigger a function as soon as I change the value of input. How do I achieve that?

    • @leighhalliday
      @leighhalliday  4 года назад +1

      Hey Shubham! Maybe do something like this rather than `handleChange` as is used in the video:
      event => {
      somethingCustom(event);
      handleChange(event);
      }

    • @samiles171094
      @samiles171094 4 года назад

      Leigh Halliday how do I pass the event? In the video when handlechange in called, no event was passed to it.

  • @raboija
    @raboija 5 лет назад

    I want the button to be disabled by default until the inputs are validated, so the user can't press it when there is no data or errors, how do i do that?

    • @leighhalliday
      @leighhalliday  5 лет назад

      There are 3 values you can use I believe... `values`, which contains all the data your user has entered, `touched`, which tells you which fields have been touched (focus + blurred), and `isSubmitting`, which is a boolean for whether the form is currently submitting. I think you may want to create a little function like `canSubmit` which looks at these 3 variables and ensures there is data, a field has been touched, and you aren't currently submitting.

  • @raboija
    @raboija 4 года назад

    I cant access values out of formik, and I find a way to do so, like link state to values its unchanged

    • @leighhalliday
      @leighhalliday  4 года назад +1

      Hey Oussama! In this article I go into a bit more detail about that showing how to use Formik together with Google Autosuggest... read through this and let me know if it helps clarify: www.telerik.com/blogs/forms-in-react

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

    Wow

  • @veliea5160
    @veliea5160 4 года назад

    I have a custom component: Could you guide me how can autofocus next field upon pressing enter as in your tutorial. Currently if I press enter, submit button is invoked and since other fields are empty, i see the validation error for each field?
    const PortInput = ({
    onKeyUp,
    innerRef,
    onChange,
    type,
    field, // { name, value, onChange, onBlur }
    form: { touched, errors }, // also values, setXXXX, handleXXXX, dirty, isValid, status, etc.
    ...rest
    }) => {
    return (
    {field.name.toUpperCase()}
    {touched[field.name] && errors[field.name] && (
    {errors[field.name]}
    )}
    );
    };

    • @leighhalliday
      @leighhalliday  4 года назад

      Hey velie! Normally in a form I think of enter as a shortcut to submit the form, not something that will take me to the next field... that's what I use tab for. I would stick with standard browser functionality which already does this rather than trying to change behaviour.

  • @christianquispecamasca3491
    @christianquispecamasca3491 4 года назад

    Hola, gracias, podrías hacer el mismo tutorial pero en español?

    • @leighhalliday
      @leighhalliday  4 года назад

      Hola Christian! Lo intentaré! Estoy planeando otro video usando forms, y ese video haré en español tambien. Saludos!

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

    Very similar to how Angular handles forms

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

      Check out my video on react hook form for another alternative :)

  • @BobbyBundlez
    @BobbyBundlez 4 года назад

    def something that by the time i learn it its old news. i spent weeks on express validator shit now i see this? FMLL

    • @leighhalliday
      @leighhalliday  4 года назад +1

      Don't need to learn everything... just build stuff! What you choose to build it in doesn't matter to the user. For everything you know in tech, there's 10 things you don't... something you just have to forget about.

    • @BobbyBundlez
      @BobbyBundlez 4 года назад

      @@leighhalliday true that man. thanks

    • @BobbyBundlez
      @BobbyBundlez 4 года назад

      @@leighhalliday this honestly changed my perspective and made me realize my worth as a dev right now. been studying a year. i took a course on treehouse then moved over to udemy and took a JS vanilla IN DEPTH course from 2020 thats went through JS, express, node, and npm stuff really well.. i recently moved on to react... my initial plans were to be a frond developer and i still have yet to apply to jobs as i am halfway through learning react. but i guess what im wondering is u think at this point i should just really aim to become a MERN stack developer? i dont want my skills to be wasted and often i feel like since i learned react im not utilizing my backend knowledge or really a lot of my vanilla js skills in the same way or atleast as much as i would like to.... whats your experience? ive just finally started building my own big projects and its been about a year since i start picking up coding. if you have any thoughts let me know... would love some more advice and guidance because that comment really helped me realize the product is what matters not all the new crazes in tech.

    • @leighhalliday
      @leighhalliday  4 года назад

      Hey Bob! Hmm, well, I think maybe as you build React websites, you could also build the backend for them, so you can develop both of those skills at once. It's probably better to focus on one or the other, but being a fullstack developer is great too! My suggestion was more against learning 15 backend frameworks... go deep on one of them and build actual projects with them.
      If you were to build 4 high quality fullstack apps, deploy them, have a good README explaining what they do, test them, and highlight them in your portfolio, this is all you need. You don't need 500 examples of React stuff you've built.

  • @mithuns8410
    @mithuns8410 4 года назад

    Could you please add Form Field Array Too.. New Subscriber here!!

    • @leighhalliday
      @leighhalliday  4 года назад

      Hey Mithin!! Thanks for the subscribe. I'll add it to my list of things I can cover in the future :)

  • @juniorbatista2463
    @juniorbatista2463 5 лет назад

    It's not html is JSX

  • @alex_chugaev
    @alex_chugaev 5 лет назад

    None of React libraries can make work with forms as simple as in Angular or Vue

    • @trungung1
      @trungung1 5 лет назад +3

      I learn both React and Vue. Vue kinda abstracts away the problems of data flow with forms. On the other hand, React makes us understand the dataflow of form. It actually comes down to preferences.

    • @dominikseljan3043
      @dominikseljan3043 5 лет назад +3

      Angular... no thanks.

    • @alex_chugaev
      @alex_chugaev 5 лет назад

      @@dominikseljan3043 Why? What you don't like about Angular? Just intersting.

    • @dominikseljan3043
      @dominikseljan3043 5 лет назад

      @@alex_chugaev It's bloated, a lot. I like simplicity of React and Vue.