Complete the code to import the ImagePicker module from expo-image-picker.
import * as [1] from 'expo-image-picker';
The correct import is ImagePicker from 'expo-image-picker'. It is case sensitive.
Complete the code to launch the image library picker asynchronously.
const result = await ImagePicker.[1]Async();The method to open the image library is launchImageLibraryAsync().
Fix the error in the code to check if the user cancelled the image picking.
if (!result.[1]) { console.log('User cancelled image picking'); }
The correct property is canceled (with one 'l') to check if the user cancelled.
Fill both blanks to request permission and check if granted before picking an image.
const [1] = await ImagePicker.[2]Async(); if (!permission.granted) { alert('Permission is required!'); return; }
You must request media library permissions with requestMediaLibraryPermissionsAsync() and store the result in a variable like permission.
Fill all three blanks to create a button that opens the image picker and sets the selected image URI in state.
const [image, setImage] = React.useState(null);
async function pickImage() {
const result = await ImagePicker.[1]Async();
if (!result.[2]) {
setImage(result.[3]);
}
}
return (
<Button title="Pick an image" onPress={pickImage} />
);The function launchImageLibraryAsync() opens the image picker. The property cancelled tells if the user cancelled. The image URI is in uri.