DEV Community

Bup Lucas
Bup Lucas

Posted on

Use useState + constructor? (is it viable?)

Good night guys, how are you?

What alternative would you have for this: use the useState hook, storing a constructor(class), centralizing data from an Interface as the main object and, in parallel, functions related to it (they handling the interface data and sending it to a service (api), handling the return and returning it to the component that has the State.)

Does this alternative of mixing the Hooks with an old building seem valid? With it, it is possible to apply SOLID and create a giant dependency on API calls by the service, the management of objects and their interactions with the Backend through classes, and using components/views as a unique and exclusive treatment of returns (100% frontEnd ).

Observation:

  • Alternatives like useReducer serve well for the data interface ahead, but it doesn't allow me to keep my main object with its interfaces and that I can use its data to build a series of functions without being the blessed actions with the using a switch case?

I'd love a third-party opinion!

Top comments (0)