期望bindActionCreators为键'ACCOUNT_LOGIN'的函数actionCreator,而是接收类型'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);
Run Code Online (Sandbox Code Playgroud)
行动:
export const ACCOUNT_LOGIN = 'ACCOUNT_LOGIN';
export function login(username, password) {
return {
type: ACCOUNT_LOGIN,
username,
password,
loggedIn: false,
loading: false
};
...
Run Code Online (Sandbox Code Playgroud)
减速器:
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
});
}
Run Code Online (Sandbox Code Playgroud)
错误:
Lio*_*l T 11
你是export一个const蚂蚁_ACCOUNT_LOGIN_然后importing * as AccountActions.
由于v3.7.0 redux警告非Action Actionor不是一个函数.在pull请求中查看更多内容.
尝试导入必要的操作,例如:
import { login, … } from '../actions/account'
Run Code Online (Sandbox Code Playgroud)
无论如何,对于我测试的内容,应用程序的功能应该正常工作,但可能会显示一堆警告.
没有直接相关的提示:您可以直接在方法中使用动作创建者connect():
import { login, … } from '../actions/account'
// …
export default connect(mapStateToProps,{
login,
…
})(account);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2916 次 |
| 最近记录: |