How to Create Pick Document File in React Native?
Hi Guys,
Now, let's see post of pick file example 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. you can understand a concept of how to pick document file in react native. I would like to share with you how to use pick document file in react native. So, let's follow few step to create example of react native pick document file example.
Let's start following example:
Step 1: Download ProjectIn the first step run the following command to create a project.
expo init ExampleAppStep 2: Install and Setup
In this step, you can install expo-document-picker:
expo install expo-document-pickerStep 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...