reading-notes

Class 401.15

Notes

Readings

Multiple Reducers Example

  1. Why create multiple reducers?

    Multiple reducers are created to manage different areas of the state in a more organized way. It helps in maintaining code cleanliness and separation of concerns.

  2. How would you combine multiple reducers?

    Multiple reducers can be combined using Redux’s combineReducers function. This function takes an object whose properties are different reducing functions, and merges them into a single reducing function.

  3. How will you manage state as an immutable object? why?

    State management as an immutable object is done by always returning a new state object instead of modifying the existing one. This is done to ensure predictability and simplicity of the state flow, and to facilitate debugging and testing.

Redux Docs: Using Combined Reducers

  1. combineReducers is a utility function to simplify the most common use case when writing ___ _____ .

    combineReducers is a utility function to simplify the most common use case when writing Redux reducers.

  2. Explain how combineReducers assembles the new state tree.

    combineReducers generates a function that calls every child reducer with the sliced state and combines their result into a single state object. The state produced from each reducer is stored by a key corresponding to the names of the reducers.

  3. How would you define initial state in an app using combineReducers?

    Initial state in an app using combineReducers is typically defined by providing default values in the individual reducers. The combined initial state would then be formed from the default states of each reducer.

Redux Docs: Combined Reducer Syntax

  1. Why will you want to split your reducing functions as your app becomes more complex?

    Splitting reducing functions as your app becomes more complex helps in maintaining the code’s manageability and clarity. It allows you to handle different parts of the state independently, and thus makes the code easier to understand and maintain.

  2. The _____ helper function turns an object whose values are different reducing functions into a single reducing function you can pass to ____.

    The combineReducers helper function turns an object whose values are different reducing functions into a single reducing function you can pass to createStore.

  3. What is a popular convention when naming reducers?

    A popular convention when naming reducers is to use a noun describing the state slice they manage (like todos or users) as the key name in the combined reducer object. This allows for a clearer understanding of what state is being managed by each reducer.

Things I want to learn more about

References