React Native Pick Document File Example

Jul 01, 2022 . Admin

Hi Guys,

Now, let's see post of how to implement pick document file in react native. This post will give you simple example of how to pick document file in react native. we will help you to give example of react native pick document file example. This article will give you simple example of how to use pick document file in react native. You just need to some step to done pick file example in react native.

Let's start following example:

Step 1: Download Project

In the first step run the following command to create a project.

expo init ExampleApp
Step 2: Install and Setup

In this step, you can install expo-document-picker:

expo install expo-document-picker
Step 3: App.js

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

import React, { useState } from 'react';
import { Button, View, Text, StyleSheet } from 'react-native';
import * as DocumentPicker from 'expo-document-picker';

const App = () => {
    const [file, setFile] = useState(null);

    const pickFile = async () => {

        const result = await DocumentPicker.getDocumentAsync({
            type: "application/*"
        });

        if (!result.cancelled) {
            setFile(result.name);
        }
    }
    
    return (
        <View style={styles.container}>
            <Text>{ file }</Text>
            <Button title="Pick a file from mobile" onPress={pickFile} />
        </View>
    );
}

const styles = StyleSheet.create({
    container: {
        flex: 1, 
        alignItems: 'center', 
        justifyContent: 'center',
    },
});

export default App;
Run Project

In the last step run your project using the below command.

expo start

You can QR code scan in Expo Go Application on mobile.

Output :

It will help you...

#React Native