在尝试集成redux时,我一直收到此错误。我已经检查了我的商店并在控制台上登录了store.getState()以确保,并在浏览器上返回正确的值(在下面的代码中index.js的第6行)。我之前也曾尝试在index.js中创建商店,但这没有用。我在下面附上我的代码。
index.js
import App from './App';
import * as serviceWorker from './serviceWorker';
import store from "./store/store";
import Provider from "react-redux/lib/components/Provider";
console.log(store.getState());
ReactDOM.render(
<Provider store={store}>
<React.StrictMode>
<App/>
</React.StrictMode>
</Provider>,
document.getElementById('root')
);
serviceWorker.unregister();
App.js
import React from 'react';
import './App.css';
import {BrowserRouter} from "react-router-dom";
import theme from "./config/theme";
import {ThemeProvider} from "@material-ui/core/styles";
import Mercury from './pages/Mercury';
import {Provider} from "react-redux";
const app =({store})=> {
return (
<BrowserRouter>
<ThemeProvider theme={theme}>
<Mercury/>
</ThemeProvider>
</BrowserRouter>
);
}
export default app;
store.js
import NavigationReducer from './reducers/navigationReducer';
import {createStore} from "redux";
const store = createStore(NavigationReducer);
export default store;
navigationReducer.js
const initialState = {
selectedPage : "home"
}
const reducer =(state=initialState,action)=>{
return state
}
export default reducer;
我的项目依赖项是
{
"@material-ui/core": "^4.11.0",
"@material-ui/icons": "^4.9.1",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"css-loader": "^4.2.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-redux": "^7.2.1",
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.1",
"redux": "^4.0.5",
"style-loader": "^1.2.1"
}