我的useReducer钩子不只为一种调度类型更新状态

时间:2020-04-23 09:01:03

标签: javascript reactjs react-redux react-hooks

减速器代码

function reducer(state, action) {
  switch (action.type) {
    case 'add':
      return {selectedArr: initialState.selectedArr.push(action.payload)};
    case 'all':
      return {all: !initialState.all};
    case 'remove':
      return {
        selectedArr: initialState.selectedArr.splice(
          initialState.selectedArr.indexOf(action.payload),
          1,
        ),
      };
    default:
      throw new Error();
  }
}

行动派遣

<TouchableRipple
  onPress={() => dispatch({type: 'all'})}
  rippleColor={Theme.colors.accent}
>
  <Surface style={[styles.ptpListFilterSurface]}>
    <Text>All</Text>
  </Surface>
</TouchableRipple>

有人可以帮我解决为什么这种发送方式不起作用吗?其他调度工作完美

0 个答案:

没有答案