【发布时间】:2018-10-17 17:32:13
【问题描述】:
返回时如何刷新数据?例如,如果我想编辑某些内容,然后按“返回箭头”,我想立即看到更改。
componentWillMount() {
getData("data", (res) => {
this.setState({ name: res.name, date: res.date});
var date = new moment(this.state.date);
var currentDate = new moment();
var duration = moment.duration(date.diff(currentDate)).as("days");
duration = Math.round(duration + 1).toString();
var daysLeftPercent = Math.round([duration / 340] * 100);
this.setState({ daysLeft: duration, daysLeftPercent: daysLeftPercent});
});
}
像这样,但我也想在另一个页面上按“后退箭头”时运行它。
【问题讨论】:
-
这是从屏幕 B 导航返回时访问屏幕 A 功能的方法 stackoverflow.com/a/52732960/7462666 导航返回时只需调用刷新
-
请阅读文档:reactjs.org/docs/react-component.html。您可以使用
shouldComponentUpdate(nextProps, nextState)或static getDerivedStateFromProps(props, state)
标签: react-native react-native-navigation