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

Redux: Updating the State with the Fetched Data

Redux: Updating the State with the Fetched Data

9:33
We will learn how moving the source of truth for the data to the server changes the state shape and the reducers in our app.
Watch this lesson now
Avatar
egghead.io

We will learn how moving the source of truth for the data to the server changes the state shape and the reducers in our app.

Avatar
Jiaming

Now I can understand why we persist list of data as Object in previous lectures :)

Avatar
Deoward

I don't fully understand the reasoning behind fetching the id's by filter vs. fetching all id's and then filtering on the client. For one thing the app is doubling the amount of data it needs to load since All = Active + Completed todos. Furthermore filtering on the client is faster and more responsive. This is just my way of reasoning about the problem and I could be missing something, could you perhaps shine some light on this particular implementation and possible benefits?

Avatar
Dor

byId reducer can be implemented with reduce:

const byId = (state = {}, action)=> {
    switch (action.type) {
        case "SET_TODOS":
            return action.todos.reduce((prev, current)=> {
                prev[current.id] = current;
                return prev;
            }, state);
        default:
            return state;
    }

};
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?