Skip to content

All topics  /  React Native

React Native Refresh Control Tutorial Example

React Native ·

Hi Guys,

In this blog, I will explain you how to create refresh control in react native. You can easily create refresh control in react native.

Here, I will give you full example for simply display refresh control using react native as bellow.

So let's start following step.

Step 1 - Create project


In the first step Run the following command for create project.

expo init Nicesnippets 

Step 2 - App.js

In this step, You will open App.js file and put the code.

import React from 'react';
import { RefreshControl, SafeAreaView, ScrollView, StyleSheet, Text } from 'react-native';
const wait = (timeout) => {
  return new Promise(resolve => setTimeout(resolve, timeout));
}
const App = () => {
  const [refreshing, setRefreshing] = React.useState(false);
  const onRefresh = React.useCallback(() => {
    setRefreshing(true);
    wait(2000).then(() => setRefreshing(false));
  }, []);
  return (
    <SafeAreaView style={styles.container}>
      <ScrollView
        contentContainerStyle={styles.scrollView}
        refreshControl={
          <RefreshControl
            refreshing={refreshing}
            onRefresh={onRefresh}
          />
        }
      >
        <Text>Pull down to see RefreshControl indicator</Text>
        <Text contentContainerStyle={styles.posttext}>React Native Refresh Control Example</Text>
        <Text contentContainerStyle={styles.posttext}>Nicesnippets</Text>
      </ScrollView>
    </SafeAreaView>
  );
}
const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  scrollView: {
    flex: 1,
    backgroundColor: '#ffb606',
    alignItems: 'center',
    justifyContent: 'center',
  },
  posttext:{
    textAlign:'center'
  }
});
export default App;

Step 3 - Run project

In the last step run your project using bellow command.

expo start

Output

It will help you...