Search code examples
ngrxnrwl-nx

Can (nx) feature libraries access the global state?


According to the Nx Docs, features of an application should still be moved into libraries. Of course, I can add feature-level state to each of these libraries, but what if there is a property on the global AppState that I would like to access from a feature library? I cannot import anything from the apps/ directory.

Is there a way to share state with feature libraries or should I move my features back into the apps/ directory?


Solution

  • My workaround has been to avoid a global store state. Instead, I create a dedicated, componentless module defining the forFeature() state, selectors, reducers, effects, etc. I then export all those from the dedicated module using forRoot().

    Now I can import this dedicated feature state module into independent application feature modules. As @satanTime points out, this state is not duplicated or replaced since it is added to the global state via forFeature().