Likes and reactions should feel instant.
Pattern:
User clicks like
Update UI immediately (increment count, fill heart)
Send API request
On success: Confirm with server count
On failure: Rollback and show error
Implementation:
const handleLike = async (postId) => {
const prevState = getPostState(postId);
updatePostOptimistically(postId, { liked: true });
try {
await api.likePost(postId);
} catch {
rollback(postId, prevState);
showError('Failed to like');
}
};