/组件/按钮.tsx
“客户端组件”
export const DeleteButton = ({ id }: { id: string }) => {
const deleteImageWithId = deleteImage.bind(null, id);
return (
<form
action={deleteImageWithId}
className="py-3 text-sm bg-gray-50 rounded-br-md w-full hover:bg-gray-100 text-center"
>
<DeleteBtn />
</form>
);
};
/lib/actions.ts
“服务器组件”
// Delete Image
export const deleteImage = async (id: string) => {
const data = await getImageById(id);
if (!data) return { message: "No data found" };
await del(data.image);
try {
await prisma.upload.delete({
where: { id },
});
} catch (error) {
return { message: "Failed to delete data" };
}
revalidatePath("/");
};
错误信息:
./components/button.tsx:44:7 Type error: Type '() => Promise<{ message: string; } | undefined>' is not assignable to type 'string | ((formData: FormData) => void | Promise<void>) | undefined'. Type '() => Promise<{ message: string; } | undefined>' is not assignable to type '(formData: FormData) => void | Promise<void>'. Type 'Promise<{ message: string; } | undefined>' is not assignable to type 'void | Promise<void>'. Type 'Promise<{ message: string; } | undefined>' is not assignable to type 'void | Promise<void>'. Type 'Promise<{ message: string; } | undefined>' is not assignable to type 'Promise<void>'. Type '{ message: string; } | undefined' is not assignable to type 'void'. Type '{ message: string; }' is not assignable to type 'void'.