What problem does comineReducers aim to solve?
This function is a function in the Redux library and is intended to address the problem of multiple Reducer exposure, since more than one reducer is often used by a component. This function receives an object whose attributes are the Reducer functions we defined.
Combined reducer function
import {INCREMENT,DECREMENT} from './action-types'
import {combineReducers} from 'redux'
// Manage the Reducer with count state
function count(state=1,action) {
console.log('count',state,action);
switch (action.type) {
case INCREMENT:
return state + action.data
case DECREMENT:
return state - action.data
default:
returnstate; }}// Manage the reducer of user state
const initUser = {};
function user(state = initUser,action) {
switch (action.type) {
default:
returnstate; }}export default combineReducers({
count,
user
})
Copy the code