- 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.
- How would you combine multiple reducers?
Multiple reducers can be combined using Redux's
combineReducersfunction. This function takes an object whose properties are different reducing functions, and merges them into a single reducing function.
- 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
combineReducersis a utility function to simplify the most common use case when writing _______ _________ .
combineReducersis a utility function to simplify the most common use case when writing Redux reducers.
- Explain how
combineReducersassembles the new state tree.
combineReducersgenerates 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.
- How would you define initial state in an app using
combineReducers?
Initial state in an app using
combineReducersis 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
- 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.
- The _______________ helper function turns an object whose values are different reducing functions into a single reducing function you can pass to __________.
The
combineReducershelper function turns an object whose values are different reducing functions into a single reducing function you can pass tocreateStore.
- 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
todosorusers) as the key name in the combined reducer object. This allows for a clearer understanding of what state is being managed by each reducer.
- Google Bard and ChatGPT