React Redux:即使导出,也会始终显示尝试的导入错误

时间:2018-12-14 04:35:18

标签: reactjs redux

我有一个具有以下结构的React应用

├── App.jsx
├── actions
│   ├── index.js
│   ├── post_actions.js
│   └── types.js
├── components
│   ├── PostBox.jsx
│   ├── PostsList.jsx
│   ├── index.js
│   └── styles
├── index.jsx
├── pages
│   ├── Read.jsx
│   └── index.js
├── reducers
│   ├── post_reducer.js
│   └── index.js
├── serviceWorker.js
└── store
    └── index.js

每当我创建一个新的ActionCreator并尝试使用它时,我总是会遇到错误:

Attempted import error: 'ACTION_CREATOR_NAME' is not exported from '../actions'.

即使我已经已导出,我重新启动React应用后,该错误消失,该应用即可正常运行。仅在我创建新的动作创建者时出现。

post_actions.js片段:

import {
  FETCHING_POSTS_FAILED,
  FETCHING_POSTS_SUCCESS,
  FEATCHING_POSTS,
} from './types';

import { apiFetchPosts } from '../api/post';

export const getPosts = page => {
  return async dispatch => {
    dispatch({ type: FEATCHING_POSTS });
    try {
      const { data } = await apiFetchPosts(page);
      dispatch(success(data));
    } catch (e) {
      const {
        response: { data }
      } = e;
      dispatch(error(data.error));
    }
  };
};

我的action / index.js如下所示:

export * from './post_actions';
....

组件摘要:

import React, { Component } from 'react';
import { getPosts } from '../actions';

class PostComponent extends Component {
....
}

const mapStateToProps = ({ posts} )=> {
...
}

export default connect(mapStateToProps, { getPosts })(PostComponent)

此错误使我发疯,我不知道为什么会显示它,并且在重新启动后消失了。任何人都有相同/相似的问题吗?

反应版本:16.6 Redux版本:4.0

0 个答案:

没有答案