在我的react应用中,我为它创建了store.js和rootreducer.js。在创建store.js和rootreducer.js文件之前,我的react应用程序正常工作,但在添加它之后,我实际上没有得到任何错误,但我在本地主机上的输出现在是空白的。为了在我的应用程序中包含store和reducer,我已经将provider和store导入到我的app.js文件中。如果我删除它们,我的react应用程序可以正常工作,但是通过这些导入,我在本地主机上得到一个空白屏幕。下面是我的store.js文件
import { createStore, applyMiddleware, compose } from 'redux'
import thunk from 'redux-thunk'
import rootReducer from './Reducer/rootReducer';
const initialState = {}
const middleWare = [thunk]
let store;
if (window.navigator.userAgent.includes("Chrome")) {
store = createStore(rootReducer,
initialState,
compose(applyMiddleware(...middleWare),
window.__REDUX_DEVTOOLS_EXTENSION__ &&
window.__REDUX_DEVTOOLS_EXTENSION__()
))
} else {
store = createStore(rootReducer,
initialState,
compose(applyMiddleware(...middleWare)))
}
export default store;
这是我的app。js文件
import React from 'react';
import './App.css';
import Nav from './Component/Common/Nav';
import 'bootstrap/dist/css/bootstrap.css';
import Welcome from './Component/Welcome';
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
import Dashboard from './Component/Dashboard/Dashboard';
import CreateMonthWallet from './Component/Dashboard/DashboardOperations/CreateMonthWallet';
import NotFound from './Component/Common/NotFound';
import { Provider } from 'react-redux';
import store from './Store';
//import { BrowserRouter as Router, Route, Routes } from 'react-router-dom';
function App() {
return (
<Provider store={store}>
<Router>
<div>
<Nav />
<Routes>
<Route path="/" element={<Welcome />} exact />
<Route path="/Dashboard" element={<Dashboard />} exact />
<Route path="/CreateMonthWallet" element={<CreateMonthWallet />} exact />
<Route path="*" element={<NotFound />} exact />
</Routes>
</div>
</Router>
</Provider>
);
}
export default App;
这是我的rooproducer .js文件
import {combineReducers} from 'redux'
export default combineReducers({
});
你可以像这样在app.js中添加你的商店
代码
import store from './Store';
添加这个
import {store} from './Store';
希望这对你有帮助!