【问题标题】:react-native Reload Flastlist per each new Focus每个新焦点的 react-native Reload Flatlist
【发布时间】:2019-04-22 14:50:38
【问题描述】:

当网页第二次返回屏幕时如何重新加载屏幕(在标签导航器中):

   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();
}

但是没有重新加载/不会发生任何事情!

我该怎么做?

【问题讨论】:

    标签: react-native react-navigation react-native-flatlist


    【解决方案1】:

    你试过了吗?

    this.didFocusListener = this.props.navigation.addListener(
    'didFocus',
       () => { this.setState({
      refresh: !this.state.refresh, products: [...this.state.products]
      }) },
    );
    

    【讨论】:

      猜你喜欢
      • 2019-07-04
      • 2018-12-27
      • 1970-01-01
      • 1970-01-01
      • 2018-04-05
      • 2018-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多