I have a function from actions folder that fetches a url using axios and that has worked. But it's getting the data from reducer that isn't working for some reason. I have mapStateToProps function defined
function mapStateToProps(state) {
return {
popular: state.popular.results
};
}
and I connect it using redux connect function
export default connect(mapStateToProps, actions)(Search);
But when i try to print the data, it gives me undefined
switch (this.props.popular){
case null:
console.log(this.props.popular);
return;
case false:
console.log(this.props.popular);
return;
default:
console.log(this);
return;
}
The default in the switch case returns an object that contains the data
As you can see in props.popular, there is an array of objects, but when i try to print this.props.popular in the default case in the switch statement, it get undefined. Why does it show that the array exists when i just print this
, but when I try to print this.props.popular
, it doesn't seem to be able to understand it. What am i doing wrong?
您的default
情况下应该包含一些内容,因为redux使用它自己的一些动作进行初始化,因此,当您进行分派时,此reducer已经返回undefined
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.