如何更新减速机的状态?

时间:2018-02-28 12:38:48

标签: reactjs react-native redux react-redux reducers

我希望在执行ACTIVITIES_SEND_SUCCESS时通过将新数据附加到对象activitiesData的末尾来更新activitiesData的状态。

  

ActivitiesReducer.js

<div>
<input type="hidden" ng-model="myVar" ng-init="myVar = 'stringformat'">
<div ng-if="myVar =='stringformat'">
<h1>Welcome</h1>
<p>Welcome to my home.</p>
</div>
</div>

1 个答案:

答案 0 :(得分:0)

您可以使用spread operator syntax

附加数据
export default (state = INITIAL_STATE, action) => {
  switch (action.type) {
    case ACTIVITIES_FETCH_SUCCESS:
      return { ...state, activitiesData: action.payload };
    case ACTIVITIES_SEND_SUCCESS:
      return { ...state, activityCreated: action.payload, activitiesData: {...state.activitesData, ...action.payload }  };
      case SUBACTIVITY_SEND_SUCCESS:
      return { ...state, listActivity: action.payload};
    default:
      return state;
  }
};