Attempted import error: 'PostsReducer' is not exported from './store/reducers/posts_reducer'

Attempted import error: 'PostsReducer' is not exported from './store/reducers/posts_reducer'

我一直在努力解决我的问题,但我一无所获。我在尝试编译我的 React 应用程序时收到以下消息:

./src/context_state_config.js
Attempted import error: 'PostsReducer' is not exported from './store/reducers/posts_reducer'

这是我的减速器文件:

import * as ACTION_TYPES from '../actions/action_types'

const initialState = {
  post: [],
  comments: []
}

const PostsReducer = (state = initialState, action) => {
  switch(action.type) {
    case ACTION_TYPES.FETCH_DB_POSTS:
      return {
        ...state,
        posts: action.payload
      }
    case ACTION_TYPES.REMOVE_DB_POSTS:
      return {
        ...state,
        posts: []
      }
      case ACTION_TYPES.FETCH_POST_COMMENTS:
        return {
          ...state,
          comments: action.payload
        }
      case ACTION_TYPES.REMOVE_POST_COMMENTS:
        return {
          ...state,
          comments: []
        }
        
      default:
        return state
      }
}

export default PostsReducer;

这是我的 context_state_config.js 导入:

import React, { useReducer } from 'react';
import Context from './utils/context';
import * as ACTIONS from './store/actions/actions';

import * as Reducer1 from './store/reducers/plain_reducer';
import * as AuthReducer from './store/reducers/auth_reducer';
import * as PostsReducer from './store/reducers/posts_reducer';
import * as FormReducer from './store/reducers/form_reducer';

import Routes from './routes';

import Auth from './utils/auth';

我有什么容易遗漏的吗?我画的是空白

您的 posts_reducer 文件中没有命名导出。只有一个出口,即 default 出口。

而不是这个:

import * as PostsReducer from './store/reducers/posts_reducer';

您应该只导入默认值:

import PostsReducer from './store/reducers/posts_reducer';