對於Redux及其概念,特別是中間件,我真的很陌生,所以我對任何愚蠢的錯誤表示歉意。繼續收到'dispatch'undefined與redux-promise
在這個項目中我的,我需要使用終極版-的thunk。我已經看過一些關於如何應用它們的指南和解釋。然後我不斷收到一個錯誤「Uncaught TypeError:無法讀取屬性'調度'的未定義」。我打開了開發工具,結果被顯示此錯誤:
我不知道,如果我做任何事情的權利。以下是我的動作創作者和商店的代碼。
動作/ index.js
import axios from 'axios';
export function fetchLessons() {
console.log('called!');
return function(dispatch) {
axios.get(`${ROOT_URL}/lessons`)
.then((response) => {
dispatch(fetchLessonsSuccess(response))
})
.catch((err) => {
dispatch(fetchLessonsError(err))
})
}
}
function fetchLessonsError(){
return "An error has occured";
}
function fetchLessonsSuccess(response) {
return {
type: FETCH_LESSONS,
payload: request
};
}
index.js(店)
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware, compose } from 'redux';
import { Router, browserHistory } from 'react-router';
import rootReducer from './reducers/index';
import routes from './routes';
import promise from 'redux-promise';
import thunk from 'redux-thunk';
const middleware = applyMiddleware(promise(), thunk);
const store = createStore(rootReducer, compose(middleware));
ReactDOM.render(
<Provider store={store}>
<Router history={browserHistory} routes={routes} />
</Provider>
, document.querySelector('.container'));