CombineReducer Name Reducer

by Victor Santos

JavaScript

//Reducers

  const nameReducer = (state, action) => {
    switch (action.type) {
      case "CHANGE_NAME":
        return { ...state, name: action.payload };
      default:
        return state;
    }
  };
  
  
  //State
  const initialState = {
  	nameReducer: {
    	name: ""
    }
  }
  
  
  //Testing Name Reducer
  const actionName = (payload) => ({ type: "CHANGE_NAME", payload });
  console.log("This is my initial value: ", initialState.nameReducer.name );
  const reducer1 = nameReducer(initialState.nameReducer, actionName("John Lock"))
  console.log("This is the name value after first dispatch", reducer1);
  const reducer2 = nameReducer(initialState.nameReducer, actionName("Alex Pen"))
  console.log("This is the name value after second dispatch", reducer2);