尝试导入错误:'./redux/reducers/configureStore'不包含默认导出(作为"配置存储"导入)



我开始学习React+Redux,我正在做一个添加或删除计数器的简单应用程序。

但我的减速器有问题。我尝试了很多事情都没有结果。。。

提前感谢:(

这是我的代码:

减速器:

import * as actionTypes from "../actions/actionTypes"

const counterReducer=(state=0,action)=>{
let newState;
switch (action.type) {
case actionTypes.INCREASE_COUNTER:
return (newState=state+action.payload);

case actionTypes.DECREASE_COUNTER:
return (newState=state-action.payload);
case actionTypes.INCREASE_BY_TWO_COUNTER:
return (newState=state+action.payload);

default:
return state;
}
};
export default counterReducer;

减速器的连接(我知道这不是没有用,但将来必须结合减速器(:

import { combineReducers } from "redux";
import counterReducer from "./counterReducer";
const reducers=combineReducers({
counterReducer
});

export default reducers;

index.js:

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import configureStore from './redux/reducers/configureStore';
import {Provider}  from "react-redux";

const store=configureStore
ReactDOM.render(
<React.StrictMode>
<Provider store={store}>
<App />
</Provider>
</React.StrictMode>,
document.getElementById('root')
);

看看这个例子:

https://redux.js.org/usage/configuring-your-store#the-解决方案配置存储

你好像在这里错过了很多。

你的const store=configureStore应该是const store=configureStore(),而configureStore函数的完整实现似乎缺失了?

一般来说,您的错误是因为在您的文件中/redux/reducers/configureStore,没有默认导出,如:export default configureStore

项目路径:/src/redux/reducers/configureStore.js:

import {createStore} from "redux"
import reducers from "./index";
export default function configureStore(){
return createStore(reducers)
}