Deleting Destinations
This guide demonstrates building functionality for your users to delete their destinations.
Step 1: Creating a deleteDestination
function
deleteDestination
functionIn your frontend, call the useDeleteDestination
hook to generate a function that fetches a scoped auth token and uses it to delete the destination scoped by the token. Leverage one of the fetchToken
functions you wrote in Building an "Add Destination" Connection Form here to create one.
const deleteDestination = useDeleteDestination(
fetchToken, // fetchToken implementation, takes an ExistingDestination
"app.example.co", // the origin of your React app (used to allow CORS),
PREQUEL_HOST // Optional (default api.prequel.co): the host url of your Prequel API
);
Step 2: Using deleteDestination
deleteDestination
Use deleteDestination
created in Step 1 to delete the given destination.
const DestinationView = () => {
// Deletion function creation elided
// Async function deletes destination using Prequel API
async function onDelete(existing: ExistingDestination) => {
const response = await deleteDestination(existing);
if (response.status === "success") {
// Handle success
} else {
// Handle failure
}
};
return (
<button type="button" onClick={onDelete}>Delete destination</button>
);
}
Updated 5 months ago