B
B
bernex2016-12-21 08:24:19
React
bernex, 2016-12-21 08:24:19

How to access the entire store from a reducer?

Using one root-reducer is not ideologically correct. You have to break it down into several.
As I understand it, for each "key" state there must be a reducer.
For example, in my state there are elements with keys: users (each has a tags array with tag ids), tags, selectedUserId
users and tags - two different reducers and one I don’t know about the existence of each other.
Okay, but if I need to get what kind of tag the user has?
If I need to do this, I don’t have a main reducer at all, only for individual fields, I can’t process the action for all data, because combineReducers does not allow you to make the main one as well.
The reducer for selectedUserId is separate, write the selected user right away, don't you need to check if the user exists in users?
Or is it such a concept and should be followed, because. you can “bicycle”, spoil and harm yourself because you have another habit in your head, where classes and scopes are, and you can always access any data.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim, 2016-12-21
@maxfarseer

- combineReducers can be used not only at the root level.
- try not to bother "right / wrong", but just do as you like, and if difficulties begin to arise, redo it.
PS cool about reducers is described in the second tutorial from Dan (creator of redux). You can also watch the first one if you haven’t watched it yet (both are in English, but the speech is understandable + there is a transcription (text) for each video))

E
edk55, 2016-12-29
@edk55

I don't understand why you need access from one reducer to another? Get a list of all tags
into the container via connect , run through the id 'tags of the user and display them.
After receiving all users, you can call the action creator (selectUser), to which you will pass the id of the selected user and write down the ID (!!!) in the store.
To display the "selected user", connect a list of all users to the container via connect , and display the desired user by ID.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question