Reactjs 如何使用refreshControl在React Native ScrollView中进行刷新?
现在我想下拉一个scrollView并刷新这个组件,所以我遵循了react native中提到onRefresh和RefreshContorol的官方文档 然而,我不知道为什么我的代码不工作,并得到错误 下面的代码是我的代码Reactjs 如何使用refreshControl在React Native ScrollView中进行刷新?,reactjs,react-native,Reactjs,React Native,现在我想下拉一个scrollView并刷新这个组件,所以我遵循了react native中提到onRefresh和RefreshContorol的官方文档 然而,我不知道为什么我的代码不工作,并得到错误 下面的代码是我的代码 <View style={styles.container}> <ScrollView contentContainerStyle={{ flexDirection: 'row', flexWrap: 'wrap' }}
<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>
{this.renderItemBox()}
下面是示例代码,您可以在其中找到与ScrollView集成的RefreshController:
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}
/>
}
/>
);
}
}
从'react native'导入{ScrollView,RefreshControl};
类RefreshableList扩展了组件{
建造师(道具){
超级(道具);
此.state={
刷新:错,
};
}
_onRefresh=()=>{
this.setState({刷新:true});
fetchData()。然后(()=>{
this.setState({刷新:false});
});
}
render(){
返回(
);
}
}
您可以添加错误吗?请添加您在执行此代码时遇到的错误。每次拉取请求时,新数据都会保持重复@尼马尔辛