gpt4 book ai didi

reactjs - bindActionCreators 期望键 'ACCOUNT_LOGIN' 的函数 actionCreator ,而不是收到类型 'string'

转载 作者:行者123 更新时间:2023-12-03 13:25:47 26 4
gpt4 key购买 nike

bindActionCreators expected a function actionCreator for key 'ACCOUNT_LOGIN', instead received type 'string'.

今天,我突然开始在应用程序中的所有 bindActionCreators 中收到此错误。
我什至查阅了较旧的 GIT 历史记录,我确信我没有遇到此错误,现在它也在那里。
该应用程序仍然可以运行,但每个路线上弹出的错误都会发生变化。

以前有人遇到过这个问题吗?或者知道它可能来自哪里?如果以下还不够,我可以提供更多代码。

容器:

import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';

import account from '../components/account';
import * as AccountActions from '../actions/account';

function mapStateToProps(state) {
return {
username: state.account.username,
password: state.account.password,
loggedIn: state.account.loggedIn,
registred: state.account.registred,
loading: state.account.loading,
clientId: state.account.clientId
};
}

function mapDispatchToProps(dispatch) {
return bindActionCreators(AccountActions, dispatch);
}

export default connect(mapStateToProps, mapDispatchToProps)(account);

行动:

export const ACCOUNT_LOGIN = 'ACCOUNT_LOGIN';

export function login(username, password) {
return {
type: ACCOUNT_LOGIN,
username,
password,
loggedIn: false,
loading: false
};
...

reducer :

import {
ACCOUNT_LOGIN,
} from '../actions/account';

type actionType = { type: string };

const initialState = {
username: '',
password: '',
loggedIn: false,
registred: false,
loading: false,
clientId: ''
};

export default function account(state = initialState, action: actionType) {
switch (action.type) {
case ACCOUNT_LOGIN:
return Object.assign({}, state, {
username: action.username,
password: action.password,
loggedIn: action.loggedIn,
loading: action.loading
});
}

错误:

enter image description here

最佳答案

您是export正在寻找const ant 作为 _ACCOUNT_LOGIN_ 然后 import ing * as AccountActions .

v3.7.0 redux警告非 Action Creator 不是一个函数。查看更多the pull request .

尝试导入必要的操作,例如:

import { login, … } from '../actions/account'

无论如何,对于我的测试,应用程序的功能应该正常工作,但可能会显示一堆警告

<小时/>

不直接相关的提示:您可以直接在 connect() 中使用 Action 创建者方法如下:

import { login, … } from '../actions/account'

// …

export default connect(mapStateToProps,{
login,

})(account);

关于reactjs - bindActionCreators 期望键 'ACCOUNT_LOGIN' 的函数 actionCreator ,而不是收到类型 'string',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44630850/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com