Migrating from the old document-picker
The new package has a new name (@react-native-documents/picker), so you need to update your import statements.
Migrating your code
Good news: You need to make only a few changes:
- update import statements
import { ... } from 'react-native-document-picker'
becomes
import { ... } from '@react-native-documents/picker'
Also, if you previously used a default import like this:
import DocumentPicker from 'react-native-document-picker'
you should update it to use named imports for the methods you need (such as pick, keepLocalCopy, etc):
import { pick, keepLocalCopy } from '@react-native-documents/picker'
- remove
pickSingle
Replace pickSingle with pick:
const result = await pickSingle(options)
becomes:
const [result] = await pick(options)
- replace
copyTowithkeepLocalCopy
This change makes your app more responsive: previously you'd use the
copyTooption and before the returnedPromiseresolved, you needed to wait not only for the user to pick the file, but also for the file to be copied to your app's directory. For large files or with slow network, this could be a problem that you, as a dev don't see, but your users do.
const localCopy = await pick({
copyTo: 'documentDirectory',
})
becomes
const [file] = await pick()
const [localCopy] = await keepLocalCopy({
files: [
{
uri: file.uri,
fileName: file.name ?? 'fallbackName',
},
],
destination: 'documentDirectory',
})