store icon indicating copy to clipboard operation
store copied to clipboard

🚀[FEATURE]: Component-level state management

Open LuisTovar0 opened this issue 1 year ago • 2 comments

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:

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.

LuisTovar0 avatar Apr 11 '23 11:04 LuisTovar0

Agree. It would be a great feature. Would want to have it 2 years ago 🙂

dhutaryan avatar May 16 '23 09:05 dhutaryan

We have an open RFC for this. We would love to hear your feedback and/or ideas on this: #1979

markwhitfeld avatar May 16 '23 12:05 markwhitfeld