A
A
Alexey Nikolaev2020-09-22 21:18:30
React
Alexey Nikolaev, 2020-09-22 21:18:30

How to build communication between reducers, and is it worth it?

Goodnight.
There is a state slice (one reducer), which stores a list of entities from the API, the isLoading flag and at the same time search data: a filter and results. I would like to break this into several slices, so that one is strictly data, the other is strictly filter, the third is strictly search, but when I started doing this, I ran into difficulties.

By concept, the reducer should only manage its own state slice. So essentially I can call one reducer from another, but that's weird, and the redux-toolkit itself is built to be unnatural.

How to be? Make a higher-order reducer that includes the union of the above reducers? Or is it better to leave one big reducer after all?

Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Cheremkhin, 2020-09-22
@Che603000

I can call one reducer from another

No need).
action goes to every reducer in the store. .
Each reducer reacts to the same one in its own way actionand analyzes it
payloadsets its own state
Current that one reducer selects data from the payload, another filter, etc.

S
Sergey Suntsev, 2020-09-22
@GreyCrew

Think "model".
those. you have one functional that responds to all requests.
I would refactor and translate all requests to middleware and make some actions for them, like API_REQUEST, API_SUCCESS, API_ABORT, API_FAIL, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question