store
store copied to clipboard
🚀[FEATURE]: Component-level state management
Relevant Package
This would probably be a new package, called @ngxs/component or @ngxs/component-store
Description
Currently, it doesn't seem possible to manage state at the component level.
In other words, this would be a store with a lifecycle that matches a component's lifecycle, while being independent from the global store.
Describe the problem you are trying to solve
I was managing the state of a component using the shared store. I realized I will need more than one instance of this component to be rendered at some point. However, they cannot share the same store: they each need their own store to write and read from. So they need to manage their states locally.
Describe the solution you'd like
Something like @ngrx/component-store. That is, a Store component that can be created -- with all the reducers and selectors -- and then be injected into a component that wants to use it, so this component can initialize it and pass it around as needed.
Describe alternatives you've considered
I've considered:
- NGXS-RxAngular integration, which doesn't solve the problem because it connects to the global store
- Standalone RxAngular, which solves the problem
- A BehaviorSubject implementation, which solves the problem
- @ngrx/component-store, which solves the problem (it's what I'm using at the moment)
Despite there being working alternatives, a solution with the NGXS philosophy would be better. After all, NGXS exists because it's a better/more modern alternative to NGRX.
Agree. It would be a great feature. Would want to have it 2 years ago 🙂
We have an open RFC for this. We would love to hear your feedback and/or ideas on this: #1979