我在使用React Redux Loading Bar时遇到问题。它没有显示出来。我在root reducer中使用了不可变的js,redux不可变的库。我没有得到任何错误。如果检查元素树,则只有一个空div。我在这里犯什么错误
index.js
import { ImmutableLoadingBar as LoadingBar} from 'react-redux-loading-bar'
class Header extends React.Component {
render() {
return (
<header>
<LoadingBar />
</header>
)
}
}
reducer.js
import { combineReducers } from 'redux-immutable';
import { loadingBarReducer } from 'react-redux-loading-bar'
export function rootReducer(state = routeInitialState, action) {
switch (action.type) {
case LOCATION_CHANGE:
return state.merge({
location: action.payload,
});
default:
return state;
}
}
export default function createReducer(injectedReducers) {
return combineReducers({
route: rootReducer,
language: languageProviderReducer,
loadingBar: loadingBarReducer,
...injectedReducers,
});
}
store.js
import { createStore, applyMiddleware, compose } from 'redux';
import { routerMiddleware } from 'react-router-redux';
import createSagaMiddleware from 'redux-saga';
import createReducer from './reducers';
import { loadingBarMiddleware } from 'react-redux-loading-bar'
export default function configureStore(initialState = {}, history) {
const middlewares =
[sagaMiddleware,routerMiddleware(history),loadingBarMiddleware()];
const enhancers = [applyMiddleware(...middlewares)];
const composeEnhancers =
process.env.NODE_ENV !== 'production' &&
typeof window === 'object' &&
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
shouldHotReload: false,
})
: compose;
const store = createStore(
createReducer(),
fromJS(initialState),
composeEnhancers(...enhancers),
);
store.runSaga = sagaMiddleware.run;
答案 0 :(得分:1)
我有一个类似的问题,但是我没有使用immutable-js。但是,无论如何,我还是想发布自己的解决方案,也许会对某人有所帮助:)
因此,我按照npm页上的说明进行了所有操作,但是我错过了一个小细节:react-redux-loading-bar导出连接的容器“ LoadingBar”和LoadingBar组件本身。 (请参阅https://github.com/mironov/react-redux-loading-bar/issues/79#issuecomment-441355249)
因此,请确保导入连接的容器(LoadingBar周围没有花括号):
import LoadingBar from 'react-redux-loading-bar'
这对于许多人来说可能是微不足道的,但也许会对某人有所帮助。