DEV Community

Discussion on: React with Typescript

Collapse
theluk profile image
Lukas Klinzing

I would disagree partly. Using set state for each field will cause rendering 5 times when you want to reset all fields at once. Also if you set one field, it will rerender the app the same amount of times as it would with setFields. Your other points sound a lot like just opinions because there is no specific reason in using a eventhandler type instead of a event type. If there are reasons for your suggestions, please let us know. Would like to hear your reasons behind this

Collapse
lukeshiru profile image
LUKESHIRU • Edited on

You're wrong, if you set all fields at once, that re-renders once, the state changes don't run in place, but actually are scheduled. I explained the reasoning for the types in other comment, but is because is the actual type used by event handlers in React. If that changes, you'll get type errors that you can actually resolve :D

Thread Thread
theluk profile image
Lukas Klinzing

You are right, but as I said, partly.

"Currently (React 16 and earlier), only updates inside React event handlers are batched by default” , according to Dan Abramov.

And

"React may batch multiple setState() calls into a single update for performance”, according to React’s documentation

So it is possible, that it is not batched.