如何返回Redux Reducer的状态

时间:2016-07-20 20:37:47

标签: reactjs redux reducers

对于redux reducer步骤: 如果我只想更改initial_state的一个属性,该怎么办?例如:

class ModalVC: UIViewController, GADInterstitialDelegate 

    func interstitialWillDismissScreen(ad: GADInterstitial!) {
    self.dismissViewControllerAnimated(true, completion: nil)
}

此处我只想将const INITIAL_STATE = { signInInfo: { signin: false, name: "", email: "", ... }, changePassword: { status: false, ... } ... }; 设置为signInInfo.signin,目前,我知道的唯一方法是输入完整的" signInInfo"喜欢:

true

case SIGNIN_USER: return { ...state, signInInfo: action.payload.data }; 就像:

action.payload.data

另一个问题是,如果我想将{ signin: true, name: "Qing", email : ... } 设置为signInInfo.signin,同时还需要将falsechangePassword.status更改为false。 我该怎么办?任何人都可以给我一个提示吗?

1 个答案:

答案 0 :(得分:3)

相当简单(两个问题):

case SIGNIN_USER: return {
    ...state,
    signInInfo: {
      ...state.signInInfo,
      signin: action.payload.signin
    },
    changePassword: {
      ...state.changePassword,
      status: true
    }
  };