Skip to main content

Always confirm first

Deletion is the one operation you can’t undo. Always ask the user to confirm before deleting.

Simple confirmation with window.confirm

The quickest approach — a browser-native confirmation dialog:
window.confirm() is perfectly fine for admin tools and internal apps. It’s ugly but it works.

Custom confirmation UI

For a better user experience, build your own confirmation:
Two states: confirming (are we showing the confirmation?) and deleting (is the API call in progress?). The user clicks Delete → sees “Yes, delete” / “Cancel” → confirms → item is removed.

Updating the parent’s state

The parent removes the deleted item from its list:
.filter() creates a new array without the deleted item. This is the standard pattern for removing items from a list in React.
prev.filter(u => u.id !== userId) keeps every user whose ID does NOT match the deleted one. Simple, immutable, and correct. You’ll use this pattern alongside .map() for updates and [...prev, newItem] for creates.

The three state update patterns

You now have all the CRUD state updates:
These three lines are the entire state management for a CRUD application. Memorize them — you’ll write them in every project.
All three patterns create new arrays instead of modifying the existing one. This is immutable state updates — React requires this to detect changes and re-render. Never use .push(), .splice(), or direct assignment on state arrays.

What’s next?

You’ve built all four CRUD operations. Now let’s see the complete picture — a full example with everything wired together from backend to frontend.

Full example walkthrough

See a complete CRUD application with React and FastAPI working together