我得到类型错误:当我运行应用程序时,无法读取未定义的属性"getState",我附加了以下源代码:
这是index.js
import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter as Router } from "react-router-dom";
import App from './App';
import * as serviceWorker from './serviceWorker';
import {Provider} from 'react-redux';
import {store} from './redux/store';
ReactDOM.render(
<Provider>
<React.StrictMode>
<Router>
<App />
</Router>
</React.StrictMode>
</Provider>,
document.getElementById('root')
);
serviceWorker.unregister();
这是商店.js
import {createStore, combineReducers, applyMiddleware} from 'redux';
import thunk from 'redux-thunk';
import {composeWithDevTools} from 'redux-devtools-extension';
// Reducers
import {cartReducer} from './reducers/cartReducers';
import {getProductDetailsReducer, getProductsReducer }from './reducers/productReducers';
const reducer = combineReducers({
cart: cartReducer,
getProducts: getProductsReducer,
getProductDetails: getProductDetailsReducer,
});
const middleware = [thunk];
const store = createStore(
reducer,
composeWithDevTools(applyMiddleware(...middleware))
);
export {store};
这是我得到的输出类型错误
我需要帮助修复这个
您需要将配置的store
作为道具传递给Provider
。
ReactDOM.render(
<React.StrictMode>
<Provider store={store}>
<Router>
<App />
</Router>
</Provider>
</React.StrictMode>,
document.getElementById('root')
);