私は現在、react-router、redux、thunk、firebaseを他の技術の中で活用しているreactjsを使用しているアプリケーションに就いています。残念ながら、非同期のアクションをディスパッチすると、次のエラーが発生します。エラー:アクションはプレーンなオブジェクトでなければなりません。非同期アクションにはカスタムミドルウェアを使用します。
私はstackoverflowによって提案されたすべての同様の質問を行ったが、まだ問題を見つけることができません。
ご協力いただければ幸いです。
エラー:
app.js:54628 Error: Actions must be plain objects. Use custom middleware for async actions. at dispatch (app.js:31576) at Object.fetchBase (app.js:32220) at Object.next (app.js:63640) at app.js:54507 at app.js:54622 at
package.json
...
"react-router-dom": "^4.1.1",
"react-router-redux": "^4.0.8",
"redux-thunk": "^2.2.0",
"redux": "^3.7.1",
...
store.js
import { createStore, applyMiddleware, compose } from 'redux';
import reduxThunk from 'redux-thunk';
import { routerMiddleware } from 'react-router-redux';
import { browserHistory } from 'react-router-dom';
// Import the root reducer
import allReducers from './reducers';
// import default data
import config from './data/config';
const defaultState = {
events: [],
config,
activeGame: null,
basePath: '',
};
const router = routerMiddleware(browserHistory);
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const store = createStore(allReducers, defaultState,
composeEnhancers(applyMiddleware(reduxThunk, router)));
export default store;
Actions.jsは
...
export const fetchBase =() => {
const organizationRef = database.ref(`users/${auth.currentUser.uid}/organization`);
return dispatch => {
organizationRef.once('value', snapshot => {
dispatch({
type: ActionTypes.FETCH_BASE,
payload: snapshot.val()
});
});
};
}; // fetchBase
...
あなたのコード(実際にはアクションが呼び出されます)は実際には理解できませんが、オブジェクトの代わりにアクションが関数を返します。 – proti
ユーザがウェブサイトにログインすると、 'this.props.fetchBase()'を呼び出してfirebaseのユーザ固有のベースディレクトリを取得します。 – user3157717