[英]My app dont recognize a this.props action as a function (React - Redux)
Dont recognize my action as a function. 不承认我的行为是一种功能。
Hello, im setting up a React-Redux application, and i want to centralize the all the set.states of my projects in one unique store.First, i was trying to call an actios that gives me data of an external API (In array form), it worked well in react, and it worked well too in a friends project. 您好,我正在设置一个React-Redux应用程序,我想将我的项目的所有set.states集中在一个唯一的存储区中。首先,我试图调用一个actios,它为我提供了外部API的数据(在数组中形式),在反应方面效果很好,在朋友项目中效果也很好。 The compiler keeps telling me that the action call method is not a function. 编译器不断告诉我动作调用方法不是函数。 Thanks 谢谢
Here's the problematic function: 这是有问题的功能:
/*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);
Heres my action method: 这是我的动作方法:
const GET_LIST = 'GET_LIST';
export default {
GET_LIST,
}
export const getPokeList = list => ({ type: GET_LIST, list });
And here's my reducer: 这是我的减速器:
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;
For the moment i dont use the result data in any part of my code. 目前,我不在代码的任何部分中使用结果数据。 Thanks and excuse my english! 谢谢,请原谅我的英语!
In App.jsx you need to change the Link import to: 在App.jsx中,您需要将链接导入更改为:
import List from '../../components/List/List';
After this your reducers will be reached, etc. I made it this far after pulling down your code. 在此之后,您的reducer将会到达,等等。在拉下您的代码之后,我已经做到了。 I wasn't sure what you were trying to achieve after this, so I left it at that. 我不确定在此之后您想要达到什么目的,所以我就这样说了。
Ultimately, the issue you encountered is because you have "export default" in your Link component. 最终,您遇到的问题是因为Link组件中具有“默认导出”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.