Reactadvanced
useOptimistic for instant UI feedback before the server confirms
import { useOptimistic, useTransition } from "react";
type Post = { id: string; likedByMe: boolean; likeCount: number };
export const LikeButton = ({ post, toggleLike }: { post: Post; toggleLike: (id: string) => Promise<void> }) => {Show the result of an action immediately and let React reconcile it with the real state once the server responds, success or failure.