【问题标题】:Redux: Error: put(channel, action): argument function not a valid channelRedux:错误:put(channel,action):参数函数不是有效的通道
【发布时间】:2021-11-07 12:39:54
【问题描述】:

当我的 redux saga 函数像这样开始时,我试图将我的 isAuthenticating 状态设置为 true

export function* onSignIn({payload}) {
  try {
    yield put(isAuthenticating, true);
    const isConnected = false;
    if (isConnected) {
     // do something
      }

注意我使用的是:yield put(isAuthenticating, true);

我的动作是这样的:

export const isAuthenticating = status => {
  return {
    type: type.IS_AUTHENTICATING,
    status,
  };
};

我的减速器看起来像这样:

const initialState = {
  isAuthenticating: false,
  user: {},
  error: null,
};

export default function (state = initialState, action) {
  switch (action.type) {
    case type.IS_AUTHENTICATING:
      return {
        ...state,
        isAuthenticating: action.payload,
      };
    case type.SIGN_IN_START:
      return {
        ...state,
      };

当我尝试登录时,出现以下错误:

ExceptionsManager.js:184 Error: put(channel, action): argument function isAuthenticating(status) {
    return {
      type: type.IS_AUTHENTICATING,
      status: status
    };
  } is not a valid channel
    
The above error occurred in task onSignIn
    created by takeLatest(SIGN_IN_START, onSignIn)
    created by watchUserAuthentication
    created by startForman
Tasks cancelled due to error:
takeLatest(SIGN_IN_START, onSignIn)
takeLatest(AUTHENTICATE_START, onAuthenticate)
takeLatest(SIGN_UP_START, onSignUp)
takeLatest(RESET_PASSWORD_START, onResetPassword)

这可能是什么问题?我该如何解决?

【问题讨论】:

标签: reactjs redux redux-saga


【解决方案1】:

查看put(action)put(channel, action) 之间的区别。由于我在您的问题中没有看到任何渠道,因此我认为您应该使用前者。

isAuthenticating 是一个动作创建者,你应该使用put(isAuthenticating(true))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-05
    • 2019-05-20
    • 2021-04-26
    • 2011-02-02
    • 1970-01-01
    • 1970-01-01
    • 2018-11-24
    • 2016-11-26
    相关资源
    最近更新 更多