I'm trying to pass a function to another component in order to call it up there after a button is clicked. When I run the code below I get an error.
const [downloadUrls, setDownloadUrls] = useState<string[]>([]);
const [preview, setPreview] = useState<string[]>([]);
let promises: any[] = [];
const uploadingToFB = async () => {
setLoading(true);
try {
for (let i = 0; i < preview.length; i++) {
const productRef = ref(storage, `images/${uuidv4()}.jpg`);
promises.push(
new Promise(async (resolve, reject) => {
try {
uploadString(productRef, preview[i], "data_url").then(
(snapshot) => {
getDownloadURL(snapshot.ref).then(async (url) => {
resolve(url);
});
}
);
} catch (error) {
reject(error);
}
})
);
}
await Promise.all(promises).then((values) => {
setDownloadUrls(values);
setLoading(false);
});
} catch (error) {
console.log(error);
}
}
<ButtonSaveProduct uploadingToFB={uploadingToFB}></ButtonSaveProduct>
ButtonSaveProduct Component:
import React from "react";
type PAGEPROPS = {
uploadingToFB: () => Promise<void>;
};
export default function ButtonSaveProduct({ uploadingToFB }: PAGEPROPS) {
return (
<button
className="p-4 bg-blue-950 text-white rounded-md hover:bg-blue-200"
onClick={uploadingToFB}>
save
</button>
);
}
Type 'OmitWithTag<PAGEPROPS, keyof PageProps, "default">' does not satisfy the constraint '{ [x: string]: never; }'. Property 'uploadingToFB' is incompatible with index signature. Type '() => void' is not assignable to type 'never'.
On Vercel i got:
Type error: Page "app/ButtonSaveProduct/page.tsx" has an invalid "default" export: Type "{ uploadingToFB: () => void; }" is not valid