【发布时间】:2017-04-24 19:48:49
【问题描述】:
在我的 react 组件中,状态中有两个属性,一个在本地反应状态,另一个在 Redux 存储中。
componentWillMount() {
this.props.fetchExercise(this.props.params.id);
}
constructor(props) {
super(props);
this.state = {editeMode: false}
}
function mapStateToProps(state) {
return {currentExercise: state.currentExercise}
}
export default connect(mapStateToProps, {fetchExercise})(createNewExercisePage);
所以根据路径; /new-exe/:id Redux 中的 currentExercise 要么是空的,要么是获取了一些东西。 editeMode 在 React 中。现在我想检查currentExercise editemode:true 中是否有东西,否则它应该是错误的(根据 false 和 true,我正在显示不同的按钮)。
我在componentWillMount(){... this.setState({editeMode:_.isNull(this.props.currentExercise)})} 中尝试过(使用 lodash)
但它不起作用,它仍然是错误的。
一般来说,在这些情况下,首先应该获取一些东西然后检查它,应该是什么方法。
【问题讨论】:
标签: reactjs redux redux-thunk