我的应用程序无法将this.props操作识别为函数(React - Redux)



不承认我的动作是一个函数。

您好,我正在设置一个 React-Redux 应用程序,我想将我项目的所有 set.state 集中在一个独特的存储中。首先,我试图调用一个 actios,它为我提供了外部 API 的数据(以数组形式),它在 react 中运行良好,在朋友项目中也运行良好。编译器一直告诉我,动作调用方法不是一个函数。谢谢

这是有问题的函数:

 /*imports*/
 import { connect } from 'react-redux';
 import { getPokeList } from '../../actions/pokeList';

  componentDidMount = () => {
    const pokeUrl = `https://pokeapi.co/api/v2/pokemon/`;
    getPokeInfo(pokeUrl)
      .then(data => this.props.getPokeList(data.results)) <---
  }
 /* connection */
 const mapStateToProps = state => ({
  pokeList: state.pokeList.elements,
 });
export default connect(mapStateToProps, { getPokeList })(List);

这是我的操作方法:

const GET_LIST = 'GET_LIST';
export default {
GET_LIST,
}
export const getPokeList = list => ({ type: GET_LIST, list });

这是我的减速器:

import pokeList from '../../actions/pokeList'
const initialState = {
  list: [],
 };
const reducer = (state = initialState, action) => {
  if (action.type !== null) {
    switch (action.type) {
      case pokeList.GET_LIST:
        return { ...state, list: action.list };
      default:
        return state;
    }
  }
  return state;
};
export default reducer;

目前,我不在代码的任何部分使用结果数据。谢谢,请原谅我的英语!

在 App.jsx 中,您需要将链接导入更改为:

import List from '../../components/List/List';

在此之后,将到达您的减速器,等等。在拉下你的代码后,我做到了这么远。我不确定你在此之后要实现什么,所以我把它留在那里。

最终,您遇到的问题是因为您的 Link 组件中有"导出默认值"。

最新更新