Приложение React Native Я использую Pull для refre sh в моем свойстве Flatlist "onRefre sh" onRefre sh вызвал функцию «refreshcontrol ()», см. код ниже. Мне нужно изменить состояние "обновление" на true, прежде чем я буду получать данные из своего API. Но он выдает максимальную ошибку обновления.
export default class NotificationScreen extends Component {
constructor(props) {
super(props)
this.state = {
refreshing: false
}
}
.
.
.
.
.
refreshControl() {
const { refreshing } = this.state;
this.setState({ refreshing : true )}. // throws maximum update error
return (
<RefreshControl
refreshing={refreshing}
onRefresh={fetchNotifications.bind(this)} //fetch from API only when refreshing is true
colors={['#2B70AD']}
/>
);
};
}
Как еще я могу установить свое состояние на «refreshing: true» ??? Помогите пожалуйста !!!!
Вот так исправили. Решение:
refresh = async() => {
this.setState({refreshing : true})
try {
const notifications = await fetchNotifications();
this.setState({
notifications,
error: null,
refreshing: false
});
} catch (error) {
this.setState({
notifications: [],
error,
refreshing: false
});
}
}
refreshControl() {
const { refreshing } = this.state;
return (
<RefreshControl
refreshing={refreshing}
onRefresh={this.refresh}
colors={['#2B70AD']}
/>
);
};