spierala / mini-rx-store

MiniRx - The reactive state management platform
https://mini-rx.io
Other
169 stars 9 forks source link

Is there a way to access the root state in a reducer? #182

Closed kaminski closed 1 year ago

kaminski commented 1 year ago

Is there any way to access the root state in a reducer? This would be to read data, not to manipulate the state beyond the reducer's scope.

In our use case, we need to look up values in a map, stored in a different branch of the root-state.

spierala commented 1 year ago

Hey @kaminski ,

You can access root state in Meta Reducers. Read more about Meta Reducers in the docs: https://mini-rx.io/docs/redux-setup#meta-reducers

If it is just about reading root state you can also use store.select: https://mini-rx.io/docs/selectors Probably you should use memoized selectors in that case.

I hope that helps!

kaminski commented 1 year ago

Thanks! @spierala

I had something different in mind, but of course you are right, I could decorate the action object in the meta-reducer with whatever part of the root state is needed for lookups.