I am using Redux Toolkit and have three components with a slice for each component: A, B, C.
I need component A to dispatch an action and components B and C to react to it. How can I achieve that having all components not being dependant on each other, similar to a pub/sub pattern?
Firstly, add extraReducers in components B and C reacting to the action.
However, you risk ending up in the circular reference problem. where one component references the other and vice versa.
The authors mentions a solution on github which i had use of. Namely, separating the shared reducers into a separate file. My implementation of this is the following:
Each createAction is an action similar to the following:
const createTodo = createAction("todos/createTodo");
Result: actions used in multiple reducers without circular reference problems.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With