'Blob' 类型的参数不可分配给 'SetStateAction<typeof import("buffer")>' 类型的参数
Argument of type 'Blob' is not assignable to parameter of type 'SetStateAction<typeof import("buffer")>'
我正在尝试设置一个 Blob
值,但在使用 useState(Blob)
时它不起作用 -,-
尝试使用 null
或 String
或将其留空,这是同样的问题。
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")>' */
}
};
有什么想法吗?
我才发现这有多蠢。
不管怎样,我刚刚修好了。
Reference
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);
}
};
` ❤
我正在尝试设置一个 Blob
值,但在使用 useState(Blob)
时它不起作用 -,-
尝试使用 null
或 String
或将其留空,这是同样的问题。
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")>' */
}
};
有什么想法吗?
我才发现这有多蠢。
不管怎样,我刚刚修好了。
Reference
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);
}
};
` ❤