DEV Community

Discussion on: Hexagonal Architecture applied to typescript react project

Collapse
 
adriamoya profile image
Adria M.

Thanks for sharing! How would you approach React contexts with hexacgonal architecture? Another repo and use cases? Do you have any example? Thanks again!!!

Collapse
 
esaraviam profile image
Luis Esteban Saravia M

Thanks for your comment 🤩, First of all, you have to think about what the context is used for. Mainly the context in react is used for sharing some "global" data to avoid passing that data as props through a lot of components. if you are thinking use context to manage the state of your app to avoid using redux it's not a very recommended practice. saying this from the hexagonal architecture perspective, to use context should be enough adding some repos and use cases to grab some data from your domain. Remember the use of context is highly risky in terms of code coupling, and that coupling is one of the primary goals when we are using DDD in this case Hexagonal architecture, a better approach is to use component composition and manage the state separately.

I Hope to be Helpful

Collapse
 
adriamoya profile image
Adria M.

@esaraviam thank you so much for your thorough response. Definitely helpful! Will take your advise into consideration. Thanks for sharing your knowledge.
Best,