mrpmorris / Fluxor

Fluxor is a zero boilerplate Flux/Redux library for Microsoft .NET and Blazor.
MIT License
1.28k stars 147 forks source link

How to implement multiple components with their own instance of the same state? #197

Closed iButters closed 3 years ago

iButters commented 3 years ago

For example: How can i add multiple counters (from the tutorial), each one with its own instance of the same state?

I am new to Blazor and Fluxor and sadly there are not many resources related to Fluxor for Blazor. So i am having a hard time to find an answer.

mrpmorris commented 3 years ago

You can make your feature state an IReadonlyDictionary of key/state.

Instead of descending from FluxorComponent (which will render when any counter staye changes) subscribe to the StateChanged event on your injected state so you can check if your entry has changed in order to render.

Make sure you implement IDisposable in your component and unsubscribe.

dotnetshadow commented 3 years ago

Is it possible to have an example of this?