【发布时间】:2020-09-22 18:40:28
【问题描述】:
我正在尝试显示导航取决于 categoryURL 的变化 redux 存储和更改其他组件中的状态。 Redux 更改了 store,它运行良好。但在我的 组件“this.props.categoryUrl”不反映价值。不能 找出原因?
import React, {Component} from 'react';
import NavigationItems from './NavigationItems/NavigationItems';
import classes from './Navigation.module.css';
import {connect} from 'react-redux';
const mapStateToProps = state => {
console.log(state)
return {
categoryURL: state.categoryUrl
};
};
class navigation extends Component {
componentDidMount() {
console.log(this.props.categoryUrl);
}
componentDidUpdate(prevProps, prevState, snapshot) {
console.log('NAVIGATION!', this.props.categoryUrl);
}
render() {
let nav = null;
if (this.props.categoryUrl) {
nav = (
<div className={classes.Navigation}>
<NavigationItems/>
</div>
)
}
return (
<>
{nav}
</>
)
}
}
export default connect(mapStateToProps, null)(navigation);
【问题讨论】:
-
错字 - 根据您的
mapStateToProps应该是this.props.categoryURL
标签: reactjs redux react-redux store