qwipo
qwipo

Reputation: 169

Share common state between many reducers

So in my React-Redux app I want to have something like a console, for progress updates, error messages etc. I want this console to have it's own state, so I can easily render it with react, but at the same time I want that every other component of my app is able to write messages to this console. How do I go about this. Do I do all the logic before the reducer and then just dispatch two actions, one for the console and one for my app's component, or is there a better way to implement something like this?

Upvotes: 0

Views: 277

Answers (1)

Paul Grimshaw
Paul Grimshaw

Reputation: 21044

You create a slice of state for the console messages, with a dedicated reducer. Then your components dispatch actions, and this reducer listens to them. Remember all the actions go through all the reducers, so many reducers can listen to the same action.

Upvotes: 4

Related Questions