I have a function that captures images from the camera and gallery, but when choosing an image or capturing a photo my function is returning an object, I need to use map() so that it returns an array containing all the information from the image's URI . How could I implement map() in this case?
This is my function:
const [uriImg, setUriImg] = useState('');
function imagePickerCallback(data) {
if (data.didCancel) {
return;
}
if (data.error) {
return;
}
if (!data.uri) {
return;
}
setUriImg(data);
}
This is where I call the function
<Image
source = {{
uri: uriImg
? uriImg.uri
: 'https://socialistmodernism.com/wpcontent/uploads/2017/07/placeholder-image.png?w=640'}}
style={styles.placeholderImage}
/>
<View style={styles.optionsCamera}>
<TouchableOpacity
style={styles.button}
onPress={() =>
ImagePicker.launchCamera({},imagePickerCallback)
}>
<Text style={styles.buttonText}>Abrir câmera</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={() =>
ImagePicker.launchImageLibrary({},imagePickerCallback)
}>
<Text style={styles.buttonText}>Escolher imagem</Text>
</TouchableOpacity>
</View>
This is what appears in the console when choosing or capturing an image, an object.
LOG {"assets": [{"fileName": "rn_image_picker_lib_temp_bbd3b196-997f-4227-80aa-f0d86824969a.jpg", "fileSize": 622543, "height": 2289, "type": "image/jpeg", "uri": "file:///data/user/0/com.francaservices/cache/rn_image_picker_lib_temp_bbd3b196-997f-4227-80aa-f0d86824969a.jpg", "width": 2289}]}