DEV Community

Discussion on: React with Typescript

 
konstagap profile image
konstagap

'useReducer would be much better to deal with nested objects inside a state'

-what is the benefit of that? writing more code? setup reducer and dispatch actions when u still keep state as an object and can just copy an object and use same setState function. Same performance too. But much better.

The reason of not having to do a copy of the object every time should be compelling enough.

  • I dont understand what is wrong with making copy of object? u try save memory? u try save what?
    So when calling useState u create a state var and a method setState:
    const [state.setState] =useState('');
    when u put each value in your own useState u create a bunch of independent setState methods takes space, which can be replaced with one setState if initial state was an object. compelling enough?)))
    Lets say u have 30 fields? what a noise in code, what a waste)))

  • If somebody is expecting to have everything served on a silver plate, learning new things will be harder and harder over time 🙁

Brother, learning will be harder overtime no matter what, that is why we are here, to help and explain. dont be like that, just be good and bring to the table =)