How to Pick Document File in React Native?

Jul 01, 2022

.

Admin

How to Pick Document File in React Native?

Hi Guys,

Here, I will show you how to works how create pick document file in react native. In this article, we will implement a how to pick document file in react native. if you have question about how to implement pick document file in react native then I will give simple example with solution. This article will give you simple example of react native pick document file example. Follow bellow tutorial step of how to use pick document file 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