Architecting an Nx Workspace containing NgRx
<h1>Why and when should you use NgRx?</h1>
<p>It is often heavily debated if NgRx is overkill and actually necessary for a project, because of its complexity, which is not beneficial for every project, but a key to success for a few.</p>
<p><strong>The short answer</strong>: It depends.</p>
<p><strong>The long answer</strong>: It depends on the size of your project, the complexity of your state and the number of developers working on the project.</p>
<h1>The even longer answer:</h1>
<p>Most applications actually don’t need a fully-fledged Redux store like NgRx — <strong>until they do!</strong>.<br />
Usually, starting out with some simple service-based statemanagement is enough at first and you might be lucky and never need anything else. In fact, many applications never need anything else.</p>
<p>But sometimes you will run into a situation where you need to share state between services that are not directly related to each other. Hence, the number of dependencies between your services will increase over time and that might lead to circular dependencies in the end. This is a common problem with service-based state management and it is hard to solve once you are in that situation.</p>
<p>One way to avoid such circular dependencies is to duplicate the state and possible also the logic that is related to that state. On the one hand, this will solve the circular dependency problem but on the other hand, it will lead to a lot of code duplication and inconsistencies in your state. Additionaly, it will be hard to keep track of all the different places where the state is used and updated. This is also an obvious violation of the DRY (Don’t Repeat Yourself) principle.<br />
If you would try to synchronize the state between the different services, you would either end up with circular dependencies again or you would have to introduce your custom event system, which is not a good idea either.The easiest and most viable solution to this problem is to introduce a global state management library like NgRx. What seemed like overkill at first, now becomes a necessity that brings simplicity into a complex situation. NgRx will help you to keep track of your state and it will also help you to keep your state consistent.</p>
<p><a href="https://levelup.gitconnected.com/architecting-an-nx-workspace-containing-ngrx-5899d385ebee">Click Here</a></p>