'Argument of type 'Blob' is not assignable to parameter of type 'SetStateAction<typeof import("buffer")>'
I am trying to set a Blob value when using useState(Blob) it's not working -,-
Tried to use null or String or just leave it blank, It is the same issue.
import * as ImagePicker from 'expo-image-picker';
import Blob from 'buffer';
const [uploaded, setUploaded] = useState(false);
const [video, setVideo] = useState(Blob);
const uploadMedia = async () => {
if (uploaded) return;
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Videos,
allowsEditing: true,
aspect: [4, 3],
quality: 0,
});
if (!result.cancelled) {
const response = await fetch(result.uri);
const blob = await response.blob();
setVideo(blob); /* < Argument of type 'Blob' is not assignable to
parameter of type 'SetStateAction<typeof import("buffer")>' */
}
};
Any ideas?
Solution 1:[1]
I just found out how dumb was this.
Anyways, I just fixed it.
import * as ImagePicker from 'expo-image-picker';
declare var Blob: {
prototype: Blob;
new (): Blob;
new (request: any, mime: string): Blob;
};
const [video, setVideo] = useState(new Blob());
const [uploaded, setUploaded] = useState(false);
const uploadMedia = async () => {
if (uploaded) {
return;
}
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Videos,
allowsEditing: true,
aspect: [4, 3],
quality: 0,
});
if (!result.cancelled) {
const response = await fetch(result.uri);
let blob = new Blob();
blob = await response.blob();
setVideo(blob);
setUploaded(true);
}
};
` ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Just4you |
