This function validates that the requesting user owns the collection before allowing the verse to be removed.
This only removes the verse from the collection, not from the Bible database.
Copy
import { useMutation } from "convex/react";import { api } from "@/convex/_generated/api";import { Id } from "@/convex/_generated/dataModel";function RemoveVerseButton({ verseCollectionId, collectionId}: { verseCollectionId: Id<"collectionVerses">; collectionId: Id<"collections">;}) { const removeVerse = useMutation(api.verseCollections.deleteVerseFromCollection); const handleRemove = async () => { if (confirm("Remove this verse from the collection?")) { await removeVerse({ verseCollectionId, collectionId, userId: "user_123" }); } }; return <button onClick={handleRemove}>Remove</button>;}
The verseCollectionId parameter refers to the _id of the entry in the collectionVerses table,
not the verseId field. Make sure to pass the correct identifier when removing verses.