reactjs - 如何使用refreshControl在React Native ScrollView中刷新?

标签 reactjs react-native

现在我想下拉一个scrollView并刷新这个组件,所以我遵循了react-native中提到onRefresh和RefreshContorol的官方文档。

但是,我不知道为什么我的代码不起作用并出现错误...

下面的代码是我的代码。

   <View style={styles.container}>
    <ScrollView
      contentContainerStyle={{ flexDirection: 'row', flexWrap: 'wrap' }}
      refreshControl={<RefreshControl refreshing={this.state.refreshing}  onRefresh={this.setState({ refreshing: true })} />}
    >
      {this.renderItemBox()}
    </ScrollView>
  </View>

最佳答案

下面是示例代码,您可以在其中找到 RefreshController ScrollView 的集成:

import { ScrollView, RefreshControl } from 'react-native';

class RefreshableList extends Component {
  constructor(props) {
    super(props);
    this.state = {
      refreshing: false,
    };
  }

  _onRefresh = () => {
    this.setState({refreshing: true});
    fetchData().then(() => {
      this.setState({refreshing: false});
    });
  }

  render() {
    return (
      <ScrollView
        refreshControl={
          <RefreshControl
            refreshing={this.state.refreshing}
            onRefresh={this._onRefresh}
          />
        }
      />
    );
  }

}

关于reactjs - 如何使用refreshControl在React Native ScrollView中刷新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56033315/

相关文章:

android - React Native android fetch 网络请求错误

react-native - react native : Refresh Controll not working with ScrollView

react-native - 如何判断 Detox 正在运行测试?

reactjs - 将 props 传递给每个组件

reactjs - 如何在 React-Native 的 Navigator 的多个场景之间共享状态

javascript - 未找到 Webpack block

reactjs - 在 native react 中处理具有 onChangeText 事件属性的对象

reactjs - Recharts - 将值数组传递给 Line 组件

javascript - 有条件地检查上下文中的值,然后在 React 中的同一函数调用中登录后导航

javascript - React Native Android Flatlist 不可见