DEV Community

Discussion on: I replaced useState hook with custom one

Collapse
 
munawwar profile image
Munawwar

I did the same. My hook's named useObjectState: The first two values of return array it's same like useState.. state and setState. I expect object as input (not intended for other data types).

The third one is spreadState - it spreads the new state object with the old one at first level of the object.

The fourth one is mergeState - that does a deep merge of the new state with the old one. Helps with nested states.

This way I am able to remain sane when dealing with large number of states. The use case is same as yours - for large form UIs.