Next.js Discord

Discord Forum

UI delay

Unanswered
Dutch Smoushond posted this in #help-forum
Open in Discord
Dutch SmoushondOP
I have a like button for posts but when pressed has a slight delay, is there a way to have the ui update and have the backend update slightly after?

4 Replies

do you have a demo?
its hard to tell with that little information
demo/video/screenshot
If your like button is calling a server action directly to update the backed, you can either:
- utilize the new useOptimisticState hook to update the UI instantly and let the server action go through whenever, or
- Utilize the useTransition/React.startTransition functionality to update client state without waiting blocking the rendenring (this might very well work/not-work depending on your exact scenario)