如何重新加载屏幕当Web第二次返回屏幕时(在选项卡导航器中):
export default class BasketTab1 extends React.PureComponent {
componentDidMount () {
this.getProductsRequest();//retur
}
getProductsRequest(){
}
render() {
return (
<View style={{margin:5}}>
<FlatList
data={this.state.products}
renderItem={this.renderItem}
keyExtractor={this._keyExtractor}
extraData={this.state}
...)
}
}
我尝试将额外数据设置为布尔值。
extraData={this.state.refresh}
当我想要刷新列表时,切换布尔状态的值
constructor(props) {
super(props);
this.state = {
refresh : false
}
}
componentDidMount () {
this.didFocusListener = this.props.navigation.addListener(
'didFocus',
() => { this.setState({
refresh: !this.state.refresh
}) },
);
this.getProductsRequest();
}
但没有重装/没有发生任何事情!
我该怎么做?
你试过这个吗?
this.didFocusListener = this.props.navigation.addListener(
'didFocus',
() => { this.setState({
refresh: !this.state.refresh, products: [...this.state.products]
}) },
);