redux - rootRedux

1. split

const reducer = (state, action) => {
    switch (action.type) {
        case 'ADD_RECIPE':
            return Object.assign(
                {}, state, {
                    recipes: state.recipes.concat({name : action.name})
            });
            
        case 'ADD_INGREDIENT':
            const myIngredients = {
                        name : action.name,
                        quantity: action.quantity,
                        measure: action.measure,
                        recipe: action.recipe
                        };
            return Object.assign(
                {}, state, {
                    ingredients: state.ingredients.concat(myIngredients)
            });
            
    }
    return state;
}

1)  recipeReducer

export const recipeReducer = (recipes, action) => {
    switch (action.type) {
        case 'ADD_RECIPE':
            return 
                recipes.concat({name : action.name});
            
    }
    return recipes;
}

猜你喜欢

转载自www.cnblogs.com/xiaobin-hlj80/p/9223914.html