Create an advanced React drag-and-drop kanban board with optimistic reordering. When a card is dropped, update local state instantly and send the new order to the backend. If validation fails like a locked board, rollback the UI with a toast error.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Providing advanced React kanban with optimistic drag-and-drop
I'm creating a React kanban board using react-beautiful-dnd that supports cross-column dragging with optimistic UI updates. On drop, it updates local state immediately, calls a fake async API simulating validation (rejecting if "locked"), and rolls back with a toast error if that fails. The example includes minimal styling, multiple columns, cards, rollback logic, and toast notifications via react-hot-toast.
Below is a minimal-but-complete example of a Kanban board using react-beautiful-dnd with optimistic updates. When you drop a card, the UI updates immediately; an API call is kicked off in the background. If the backend rejects (e.g. board is locked), we roll back the UI and show a toast error.
Drag and drop: react-beautiful-dnd handles the drag events. onDragEnd receives source and destination.
Optimistic update: We compute a new columns object and set it immediately with setColumns(newColumns).
API call: We send the updated ordering to the backend (updateBoardOrder) with the column → card ID mapping.
Rollback on error: If the backend throws (e.g. the board is locked), we revert to prevColumnsRef.current and show a toast error.
Toast feedback: Uses react-toastify to show success/error messages.
Replace the updateBoardOrder function with your actual HTTP request to your backend. If your backend returns validation details (like which board is locked), propagate that into the error to display more granular messages.