Reactjs Redux thunk“;调度不是一项功能”;
我用以下方式配置了redux thunkReactjs Redux thunk“;调度不是一项功能”;,reactjs,redux,redux-thunk,Reactjs,Redux,Redux Thunk,我用以下方式配置了redux thunk import {BrowserRouter} from "react-router-dom"; import {createStore, applyMiddleware, compose} from "redux"; import Provider from "react-redux/es/components/Provider"; import braintrainer from "./store/reducers/braintrainer"; imp
import {BrowserRouter} from "react-router-dom";
import {createStore, applyMiddleware, compose} from "redux";
import Provider from "react-redux/es/components/Provider";
import braintrainer from "./store/reducers/braintrainer";
import thunk from 'redux-thunk';
const store = createStore(
braintrainer,
applyMiddleware(thunk),
);
ReactDOM.render(
<Provider store={store}>
<BrowserRouter>
<BrainTrainer/>
</BrowserRouter>
</Provider>
, document.getElementById('root'));
我将onLoginClicked函数传递给我的登录组件,并在单击登录按钮时调用它
<button type='button' className='login-btn' onClick={onLoginClicked(passWord,userName)}>
{isLogin ? 'Login' : 'Sign up'}
</button>
然而,当我调用onLoginClicked函数时,我在startLogin操作创建者中得到了这个错误
Unhandled Rejection (TypeError): dispatch is not a function
谁能告诉我哪里出了问题
错误图片
在dispatch(fn)
中,fn
需要是一个“thunk”函数-接受dispatch
本身作为第一个参数。不是匿名函数:
dispatch(()=>startogin(用户名、密码))
但是startogin
的返回值:
dispatch(startLogin(username,password))
在dispatch(fn)
中,fn
需要是一个“thunk”函数-接受dispatch
本身作为第一个参数。不是匿名函数:
dispatch(()=>startogin(用户名、密码))
但是startogin
的返回值:
dispatch(startLogin(username,password))
您的
startogin()
正在尝试访问中的调度
。然后(…调度…
),实际上这不是一件事<代码>调度在更高级别可用。尝试this.props.dispatch
或研究重构bitHm。我在他调用dispatch inside then()中遵循了这个例子,就像我说有很多代码丢失一样(比如哪里调用了onLoginClicked?哪里调用了MapDispatch Toprops?@boris grunwald尝试在你的thunk中返回承诺:返回axios.post(baseUrl+'/api/auth/login'.
。你的Startogin()
正在尝试访问中的分派
。然后(…分派…
),实际上这不是一件事。分派
更高。尝试此.props.dispatch
或研究重构bitHm。我在他调用dispatch inside()中遵循了这个示例正如我所说的那样,有大量代码丢失(比如onLoginClicked调用在哪里?mapsDispatchToprops调用在哪里?@boris grunwald尝试在您的thunk中返回承诺:return axios.post(baseUrl+“/api/auth/login”…
)。
dispatch(startLogin(username,password))