Reusable Create & Edit Form in React (React Hook Form, Zod)

  Рет қаралды 36,100

Cosden Solutions

Cosden Solutions

Күн бұрын

Пікірлер: 63
@ronniedinoy8440
@ronniedinoy8440 Ай бұрын
Thank you so much sir. this may break my stone age knowledge in programing.
@naziruadam3950
@naziruadam3950 9 ай бұрын
Thanks for this piece. I think I'll have to follow this tut typing the code myself, that way, I'll understand it better.
@rvirgorn
@rvirgorn Ай бұрын
Recently I'migrated from formik and yup to hook-forms and zod. It would be great if you could create a video with all available validations in zod. It would be great to have it in one place with your explanation. Because you are the best!
@ernestechie
@ernestechie Ай бұрын
Oh, he has a dedicated Zod + React Hook Form tutorial somewhere in his channel.
@ernestechie
@ernestechie Ай бұрын
kzbin.info/www/bejne/i2qziqyDnamWlc0si=P0GBpa-8v4zaFMya
@violabg
@violabg 9 ай бұрын
Why didn’t use Controller from react-hook-form, for DatePicker and Select
@cosdensolutions
@cosdensolutions 9 ай бұрын
You could
@rezaz7167
@rezaz7167 8 ай бұрын
How?
@rvirgorn
@rvirgorn Ай бұрын
Just add value instead of default value. Here is an example value=user?.someProperty || '''
@varshithgowdav9892
@varshithgowdav9892 8 ай бұрын
Can u please make a video on persisting user data,I'm really confused what to use .There are multiple options like local storage,redux ..etc.
@ptolemyhenson6838
@ptolemyhenson6838 8 ай бұрын
How can you create a form to allow users to create a list of arbitrary length (preferably a heterogeneous list, allowing the user to add multiple input types) using this method?
@kevinmitchell6141
@kevinmitchell6141 9 ай бұрын
Would be great to see some dynamic form content! It adds a lot of complexity I feel
@jitesh_khurana
@jitesh_khurana 9 ай бұрын
can be done by useFieldArray from react-hook-form
@kevinmitchell6141
@kevinmitchell6141 9 ай бұрын
@@jitesh_khurana yes but my point is that it can be difficult to work with + not much examples of it in the wild
@thngzys
@thngzys 9 ай бұрын
I would advice against this. Have been using rhf in prod for couple of years. I will say it does not scale well with huge or dynamic forms. Better to have individual form instances for each section, then collate the data prior to submission.
@thngzys
@thngzys 9 ай бұрын
Also, maintenance is a pain.
@KartheekJavvajiKJ
@KartheekJavvajiKJ 8 ай бұрын
@@thngzys I have reached to a similar conclusion
@dsolisg1
@dsolisg1 2 ай бұрын
Hi, thank you for your useful video. I have a question about next.js: we know we can't upload files in public folder in production environment, so, instead I'm uploading in other folder( at the same level as public) the pdfs files required, now, how can I show these pdf files inside an tag specifying the src attribute in production environment?
@stefin1
@stefin1 9 ай бұрын
Would you leave the file as is, or decompose it into smaller files?
@Kizzyman
@Kizzyman Ай бұрын
Brilliant video thank you! Quick question: Passing undefined into default values in the case of a NewForm results in an error "A component is changing an uncontrolled input to be controlled", did I miss something here? Also if I pass a default value of empty string it correctly validates my zod schema as its just needs a string so an empty string passes which is incorrect (I want it to be required), I can set a min length and print an error message or required but again doesn't feel correct. Any ideas?
@mohammedfarookabdul3387
@mohammedfarookabdul3387 26 күн бұрын
if you don't want this behaviour, use react hook forms rules behaviour. Zod has different behaviour and rules, If you want to learn more please refer zod docs
@AviCharlop
@AviCharlop 9 ай бұрын
Nice idea and video thanks. Just one note, you are already using zod, parsing the user prop with zod would have made the spread for default values unnecessary and the logic a bit cleaner
@rezaz7167
@rezaz7167 8 ай бұрын
Passing the parsed value as defaultValues?
@AviCharlop
@AviCharlop 8 ай бұрын
@@rezaz7167 exactly. Something like: defaultValues: user ? formSchema.parse(user) : undefined
@hqasmei
@hqasmei 7 ай бұрын
Great video! Question, for a delete form you'd have to create a different form right?
@jazzdestructor
@jazzdestructor 8 ай бұрын
Hey Cosden i have just one query with register onSubmit it scrolls to it and redirects to the specific field, how can i achieve validation, required, error and scrollTo for components that dont register?? i have seen something called that react hook form but i am not quite sure on it. please let me know what can be done here.
@rezaz7167
@rezaz7167 8 ай бұрын
When I pass undefined to default values (in rhf) the browser on client component gives me this warning: Changed from uncontrolled to controlled input. But when i explicitly gives {title: “”, email:””} its ok. Can someone explain a better way to tackle this issue
@devGamersCoders
@devGamersCoders 7 ай бұрын
I would like some changes to do if I was using this approach cause I would pass initialvalue from parent like add and edit page cause it is more relative than using if else same for handleSubmir fnc.
@serbanmarin-eusebiu
@serbanmarin-eusebiu 9 ай бұрын
The idea behind this video was very good and clear, but it would be more interesting if you would make a modal like with react-query under the hood. I’ve tried to create a such implementation, but it keeps falling for more than 2 use effects (linked data, one data depends on another). If you would like to create a video about this, I could give you access to the repository.
@z-aru
@z-aru 9 ай бұрын
Wouldn't simply providing a key should be possible?
@serbanmarin-eusebiu
@serbanmarin-eusebiu 8 ай бұрын
The base ideea is that you can provide a modal state, and a key for what you need, and when you open the modal, you pass to the react query the modal state and the key to enable the fetch request.
@alitonoliveira1700
@alitonoliveira1700 9 ай бұрын
How to deal with nested array? That would be awesome.
@johndevnoza4223
@johndevnoza4223 8 ай бұрын
i would love to see, react query with react hook form and zod. since imnt pro with this, react query has different approach with FORM when it comes to mutations, so i couldnt understand it by myself. anyway Great videos!
@JohnSmith-gu9gl
@JohnSmith-gu9gl 8 ай бұрын
Great video but there is a problem. lets say you have a user form. if you want to update a user, password field is optional, so your types and validations have to know that. Maybe something like this: resolver: user ? zodResolver(updateUserValidator) : zodResolver(createUserValidator) , Would be great to see how you would solve that.
@3pleFly
@3pleFly 3 ай бұрын
Same schema, add discriminator prop like form type, make password optional and if its update user form then check for password on refine. Or make it a diecriminated union figure it out
@petarmalamov2917
@petarmalamov2917 9 ай бұрын
Isn't is better to pass an onSubmit function to the component, the form component doesn't need to know what happens to the submitted data it just interested if the data is valid and you can pass only the form data, not the entire user. That way in the future if there is a 3th action the form needs to do ( can't think of one now :D ) you can just change the on submit function that you pass to the component .
@3pleFly
@3pleFly 3 ай бұрын
No. Its a user form. Its onsubmit is defined in it. This isnt some generic form component. Its a userform only. If in the future u add more fields then where do you add them? In the user form itself... where do you update the onSubmit? Also the user form...
@warrenpeace2557
@warrenpeace2557 9 ай бұрын
Any coupon code for your course please 😮
@suchitkubasad8695
@suchitkubasad8695 5 ай бұрын
Can I apply same to react native?
@navedkhan6643
@navedkhan6643 8 ай бұрын
Big fan of yours
@NikhilPatel-bq7ck
@NikhilPatel-bq7ck 9 ай бұрын
Have you ever made a video upon limitations of react-hook-forms and Formik? Is there any limitations when some more complex form with array type with multiple fields with some of theme as optional and some with lazy api call lets say some checks on db side and displaying validation like email exists. Such Comparison is bit rare in youtube. Everyone just shows very basic demos. Real usecase form are more complex and thats when only few quality content can help some to take decision which lib one should go with. If application is more complex lets say insurance company portal etc.
@mohamedsalimbensalem6118
@mohamedsalimbensalem6118 9 ай бұрын
because the majority of people watching youtube tutos are beginners
@devlhb3474
@devlhb3474 Ай бұрын
why you didn't use reset
@mDHARYL
@mDHARYL 4 ай бұрын
Thank you. I will try to refactor my code. 😅. I use to have create and editform
@tochimclaren
@tochimclaren 2 ай бұрын
Why is it so hard to pre-populate data in react. Why!
@AhmedOsama5
@AhmedOsama5 9 ай бұрын
really nice video, but I think you don't have to pass the default value for every input manually I think just can use the form default value better
@thngzys
@thngzys 9 ай бұрын
The reason why he had to pass manually is because he didn't use the Controller
@jazzdestructor
@jazzdestructor 8 ай бұрын
i think he could use getValues / watch instead of user Obj for consistency
@AhmedOsama5
@AhmedOsama5 8 ай бұрын
using user data should be done once as default values that's the correct flow based on my experience any way the tutorial is more focused on another aspect and he did well about it @@jazzdestructor
@AhmedOsama5
@AhmedOsama5 8 ай бұрын
yeb could be@@thngzys
@imkir4n
@imkir4n 9 ай бұрын
Please add server action and error handling with this combo.
@navedkhan6643
@navedkhan6643 8 ай бұрын
Can you make more video on clean code and SOLID principle
@shakapaker
@shakapaker 9 ай бұрын
I would like to see how make add edit form with images
@jitxhere
@jitxhere 9 ай бұрын
I am currently using bunnycdn to handle them
@dipanjanghosal1662
@dipanjanghosal1662 8 ай бұрын
Please make a video on jwt authentication with Redux persist
@Pareshbpatel
@Pareshbpatel 6 ай бұрын
Excellent demonstration of how to build an Edit/Add Form with React-Hook-Form and Zod. Thanks, Darius. {2024-07-09}, {2024-00-01}
@akshayc3314
@akshayc3314 9 ай бұрын
Your contents are great. Can you please cover some other tech stack apart from react. Like devops or backend .
@mohammedfarookabdul3387
@mohammedfarookabdul3387 26 күн бұрын
it's bad practise for prop drilling, need to use useform context and make it reusable anywhere. where they need this form or it's part to anywhere. You are doing some if else gimmicks. Also I am your big fan.
@ZhulienDI
@ZhulienDI 4 ай бұрын
17 minutes for a video on how to receive default values from props. Damn. People be milkin' hard.
@3pleFly
@3pleFly 3 ай бұрын
Yup ...I am pretty sure these people are jobless and shameless scamming noobs
@VkParish
@VkParish 9 ай бұрын
First comment 😜
Failed a Technical Interview Because of This Code
22:08
Cosden Solutions
Рет қаралды 4,9 М.
React Hook Form - Complete Tutorial (with Zod)
28:22
Cosden Solutions
Рет қаралды 148 М.
Cheerleader Transformation That Left Everyone Speechless! #shorts
00:27
Fabiosa Best Lifehacks
Рет қаралды 16 МЛН
When you have a very capricious child 😂😘👍
00:16
Like Asiya
Рет қаралды 18 МЛН
Курс React Hook Form за 40 минут! RED Course
39:00
RED Group +
Рет қаралды 12 М.
Compound Components in React (Design Patterns)
18:21
Cosden Solutions
Рет қаралды 51 М.
Build a Multistep Form in NextJs Using react-hook-form and ZOD
20:31
This is the Only Right Way to Write React clean-code - SOLID
18:23
This Folder Structure Makes Me 100% More Productive
24:36
Web Dev Simplified
Рет қаралды 120 М.
The Complete Guide to Modern React in 2025
33:52
Cosden Solutions
Рет қаралды 17 М.
React Hook Form & React 19 Form Actions, The Right Way
16:08
Jack Herrington
Рет қаралды 63 М.
Every React Concept Explained in 12 Minutes
11:53
Code Bootcamp
Рет қаралды 924 М.
The Biggest Mistake Intermediate React Developers Make
18:32
Cosden Solutions
Рет қаралды 47 М.
Become a Master at Reusable Components in React
19:51
Cosden Solutions
Рет қаралды 25 М.
Cheerleader Transformation That Left Everyone Speechless! #shorts
00:27
Fabiosa Best Lifehacks
Рет қаралды 16 МЛН