我无法连接记录器,我尝试了一切
import {createStore, applyMiddleware} from 'redux';
import promiseMiddleware from 'redux-promise';
import {hydrate} from 'drator';
import rootReducer from '../reducers';
import thunk from 'redux-thunk';
import {createLogger} from 'redux-logger';
const logger = createLogger();
const createStoreWithMiddleware = applyMiddleware(thunk, promiseMiddleware, logger)(createStore);
const state = hydrate('App');
export default createStoreWithMiddleware(rootReducer, state);
版本“redux-logger”:“^ 3.0.6”,
我已经使用了这个同构的Redux存储库https://github.com/ryardley/reduxor
答案 0 :(得分:1)
我可能会在没有测试的情况下出错,因为您的帖子可能会有更多细节,但看起来您正在以错误的方式调用createStore
和applyMiddleware
函数。
通常我会这样做
import logger from 'redux-logger'
const store = createStore(
reducer,
applyMiddleware(logger)
)
这种方式applyMiddleware
是createStore
请参阅此处以获取参考https://github.com/evgenyrodionov/redux-logger#usage
答案 1 :(得分:0)
这应该有效。使用compose应用中间件。
import { compose, createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import logger from 'redux-logger';
import promiseMiddleware from 'redux-promise';
import rootReducer from '../reducers';
let store = null;
export default function configureStore(initialState = {}) {
// Check to avoid multiple configured stores
if (store) {
return store;
}
const middlewares = [thunk, promiseMiddleware, logger];
store = createStore(
rootReducer,
initialState,
compose(applyMiddleware(...middlewares))
);
return store;
}