[英]I am getting this error: TypeError: store.getState is not a function
I am getting the error:'TypeError: store.getState is not a function' and I can't determine where the problem is我收到错误:'TypeError: store.getState is not a function',我无法确定问题出在哪里
here's how I created the store:这是我创建商店的方式:
import { applyMiddleware, createStore } from 'redux';
import thunk from 'redux-thunk';
import rootReducer from './rootReducer';
const initialState = {
pending: false,
products: [],
error: null
}
const middlewares = [thunk];
export const store=createStore(rootReducer, initialState, applyMiddleware(...middlewares));
and here's the index.js:这是 index.js:
import React from "react";
import ReactDOM from "react-dom";
import { Provider } from "react-redux";
import store from './App'
import App from "./App";
ReactDOM.render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById("root")
);
and here's the thunk function:这是 thunk function:
function fetchProducts() {
return dispatch => {
dispatch(fetchProductsPending());
fetch('https://api.spacexdata.com/v3/launches')
.then(res => res.json()
)
.then(
res => {
if(res.error) {
throw(res.error);
}
dispatch(fetchProductsSuccess(res.products));
return res.products;
})
.catch(error => {
dispatch(fetchProductsError(error));
})
}
}
export default fetchProducts;
and here's a sandbox of the problem:这是问题的沙盒:
https://codesandbox.io/s/polished-sunset-wxefc?file=/src/index.js https://codesandbox.io/s/poliished-sunset-wxefc?file=/src/index.js
here's a screenshot of the error:这是错误的屏幕截图:
The store
is not the default
export from the ./App.jsx
module. store
不是./App.jsx
模块的default
导出。 You either need to add curly braces to your import or export store
as the default
:您需要将花括号添加到导入或导出store
中作为default
:
// App.jsx
export const store = /* ... */
// index.js
import { store } from './App';
or或者
// App.jsx
export default const store = /* ... */
// index.js
import store from './App';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.