When calling setImage(result.uri); console.log(image) logs null when it should show me the new image uri. Interestingly the error shows up as
TypeError: null is not an object (evaluating 'props.route.params.uid')
after pickImage is called even though before it's called it has no problem evaluating it and displaying it. If I remove props.navigation.navigate("Save", image, album); and pickImage is called again, this time console.log(image); will show me the uri for the image picked earlier.
const [album, setAlbum] = useState("");
const [hasGalleryPermission, setHasGalleryPermission] = useState(null);
const [image, setImage] = useState(null);
useEffect(() => {
setAlbum(props.route.params.uid);
(async () => {
const galleryStatus =
await ImagePicker.requestMediaLibraryPermissionsAsync();
setHasGalleryPermission(galleryStatus.status === "granted");
})();
}, []);
const pickImage = async () => {
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Images,
allowsEditing: true,
aspect: [1, 1],
quality: 1,
});
console.log(result);
if (!result.cancelled) {
setImage(result.uri);
console.log(result.uri);
console.log(image);
console.log(album);
props.navigation.navigate("Save", image, album);
}
};