It depends on a few factors:
- Consequences of a mistaken deletion. Is the data to be deleted something that the user can easily recover from, like filter values in a form, or is it something that needed considerable investment?
- Need for batch-operations. Is it necessary for the user to be able to delete several (but not all) items from a list?
- Cost on other features of the page. How much do you want to prioritize this safety compared with other aspects of your page, such as speed?
Here are a few patterns:
Confirmation toast with undo button. This is really a great pattern for changes that you can be relatively confident that the user intended to do. It adds no cost to the deletion operation. It doesn't get in the way of batch operation. The only caveat is that it doesn't support a great undo depth — you can potentially stack them up but not indefinitely, so if it's important to allow the user to go back an infinite amount this wouldn't be the right pattern.
Confirmation modal dialog. This is very expensive in user terms and hampers batch operations, so should be reserved for cases where the consequences are bad and there is no need to support batch deletions.
Save/Cancel state for the page instead of save-as-you-change. When making changes on the page, the changes aren't saved but a "Save" button appears along with a "Cancel" button. This supports batch operations but it means the changes, even the completely riskless ones such as ticking a checkbox (which is just as easily unticked), aren't applied until the user hits "Save" on the page. It also requires the "Save" button to be very visible or the user might lose data another way, by forgetting to save their changes.
Complicate the dangerous gesture. Instead of a click, make it two clicks to delete something, preferably on elements not in the same spot to avoid losing the safety for compulsive double-clickers (many users always double-click). This kind of works but it adds a lot of user cost to the base case (deleting is now twice as hard always) which is really cumbersome for batch operations. For many situations, I've found it better to use a confirmation toast with undo rather than complicating the gesture.