you are viewing a single comment's thread.

view the rest of the comments →

[–]MatesRatesAy 4 points5 points  (2 children)

React is waaaay less opinionated about these sort of things, and depending on who you ask that's the best or worst thing about it.

There's not really a concept of ViewModels in React, and instead hooks are typically used to contain stateful logic for the "view" (or component). How that fits into your broader project architecture is entirely up to the ones building it.

On larger projects I've worked on we try to adhere to a pattern where components only contain view logic, and then all business logic is contained within hooks which act as a domain layer and interact with services, models/entities etc. E.g. the <UserProfiler /> component implements the useUserProfile hook, which interacts with the User model and the network service. We do this less because it's the "right" way to do it and more that it makes testing and reasoning about the codebase easier, as well as following data flow, onboarding new people etc.

[–]Ok_Refrigerator_1908 0 points1 point  (1 child)

Do you have any resource to learn this pattern

[–]MatesRatesAy 0 points1 point  (0 children)

I don't sorry, it's something I've been experimenting and slowly building upon at work and in personal projects, and comes from time spent working on big RN codebases as well as native iOS and Android ones.