Function currying in event handlers

preview_player
Показать описание
Use function currying with events in React! #react #reactjs #reactjsdeveloper #programming #progammer #frontend #coding #code
Рекомендации по теме
Комментарии
Автор

Also you can add name to input and just get from event both name and value. With that you just put function without any values onchange

Di-yes
Автор

Other way is to change function by passing only event and destructure name and value from event object

cbijay
Автор

Its intresting but we can add name attribute in the input field and can get the name, value from event in the handleChange function.

learnwithashu
Автор

Just give the inputs names that match their respective property in form state and use event to set it like [name]: value

JimmyRowe-fvcw
Автор

When working with a form is it better to use useRef for each input and get the current value or useState for each input and make handlers for onChange

uvs_
Автор

Each html element should have name prop, thats mandatory, bro you’re just breaking the a11y

grishapetrosyan
Автор

Pretty interesting, at first it's confusing to look at for the normies. But if you consider that this is Higher-Order function, now you have some perspective. It's not for beginners that's for sure, but for those that knows them, it's a great advanced tool in your arsenal.

juniferchat
Автор

One thing though: why don't we take formState from setState callback but from useState declaration above? Maybe it doesn't make a difference here but in general makes more sense

nikitarudenko
Автор

Interesting. I really think I need more knowledge to handle a function that return a function. I understand the goal: don't pass two arguments but only one but I don't like it because AO I said my lack of knowledge but also because I feel that is a more "nested" code

sobrehombre
Автор

this might work but in large amount of inputes it makes memory problems because it will run a lot of function in every render and wors on the initial mount
you can use a simple function and use name of inputs

soobhhann
Автор

Sir which tips you share is in typescript can you came up with some content with javascript

AzadKumar-zilm
Автор

Mm, yeah, but at the end you’ll still create 2 different functions references and as you don’t use useMemo on them every render will be a new one as well

So if you wanna do this better not use useState for the form and use useRef instead and on the submit btn do the required form validation so the component won’t render on each input

You can have just a single useState to force a render on Submit to give feedback to user in case the form is not valid

FERnandezJjuan
Автор

It's not currying, it's called partial application

fdddd
Автор

My lazy ass will just leave my code like it is, and that's really bad. I think if someone like him would see my React code, he would collapse 😂

smashi
Автор

Why to increase code complexity unnecessarily

pvsagar
Автор

I just use ctrl+shift+f to refactor everything

blackpurple
Автор

Why to do this when you can jist add <form> with handlesubmit. Why we would need to listen to changes?

krzysztofrozbicki
Автор

both the values were form.password bruhh..

jpxtv
Автор

But you’ll have 2 functions which you don’t need

addayounes
Автор

I would just change the handleChange function to be a named function instead of arrow function. I think it would make the function better to understand. Just my opinion

giodefreitas
welcome to shbcf.ru