【发布时间】:2018-09-20 21:36:20
【问题描述】:
我正在制作一个基于天数显示图表的 react-native 应用程序
我正在调度一个 Redux Action,它在 componentDidMount 中调用 API
componentDidMount() {
this.props.coinHistory(this.state.days, this.props.navigation.state.params.coinShortName)
this.props.coinComplete(this.props.navigation.state.params.coinShortName)
}
最初我的状态是
state = {
days: 1
}
现在,我有一个按钮可以改变上述状态
<Button
onPress={() => this.changeHistoryChart(7)}
title="Learn More"
color="#841584"
accessibilityLabel="Learn more about this purple button" />
changeHistoryChart 长这样
changeHistoryChart = (value) => {
this.setState({days: value})
this.props.coinHistory(this.state.days, this.props.navigation.state.params.coinShortName)
}
[问题:] 虽然这可行,但问题是我需要单击我的按钮两次以显示新数据或另一个按钮以显示上一个按钮的数据。我可能做错了什么,我该如何解决? (下面附上GIF供参考)
另外,如果我遗漏了任何重要的代码,请告诉我,我会在这里更新
【问题讨论】:
标签: reactjs react-native