The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Redux: Colocating Selectors with Reducers

Redux: Colocating Selectors with Reducers

4:52
We will learn how to encapsulate the knowledge about the state shape in the reducer files, so that the components don’t have to rely on it.
Watch this lesson now
Avatar
egghead.io

We will learn how to encapsulate the knowledge about the state shape in the reducer files, so that the components don’t have to rely on it.

Avatar
Kristian

In a large application won't this mean there are possibly hundreds of selector functions in the root reducer?

I wonder if there is a way to import selectors from child reducers via an import * and apply the relevant slice of the state tree to them?

Avatar
Afzal

In reducers/index.js why do we not have curly braces here?

export const getVisibleTodos = (state, filter) =>
    fromTodos.getVisibleTodos(state.todos, filter);

If I put curly braces it gives me an error (cannot read map of undefined in todolist ie not getting todos in todolist.js) and doesn't work

// doesn't work
export const getVisibleTodos = (state, filter) => {
    fromTodos.getVisibleTodos(state.todos, filter);
};
Avatar
Deep

I think it's a matter of being implicit vs explicit. What happens if you put a return before fromTodos... in your example?

In reply to Afzal
Avatar
Dean

Why can't you treat the selector like any actionCreator, because the thunk methodology will ensure ansync and allow for you to grab the state as you need. So, I don't see the reason for all this hoop jumping when you can just create the selector as an actionCreator, use getState() in it and return some value that you then can access? What am I missing?

In reply to egghead.io
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?