How to add optimistic updates for Next.js Commerce' add to cart + quantities to speed it up.
Unanswered
Transvaal lion posted this in #help-forum
Transvaal lionOP
We've implemented the cart functionality for your Next.js 14 RSC App Router ecommerce site like it is shown in https://github.com/vercel/commerce
Now we need to figure out a way to speed it up, so you don't wait for the server response every time your in/decrease the quantity amount or adds an item to the basket.
How to speed it up? Do you use React's "useOptimistic" hook or is there a better way? Any example of this would be greatly appreciated.
Now we need to figure out a way to speed it up, so you don't wait for the server response every time your in/decrease the quantity amount or adds an item to the basket.
How to speed it up? Do you use React's "useOptimistic" hook or is there a better way? Any example of this would be greatly appreciated.
2 Replies
@Transvaal lion We've implemented the cart functionality for your Next.js 14 RSC App Router ecommerce site like it is shown in https://github.com/vercel/commerce
Now we need to figure out a way to speed it up, so you don't wait for the server response every time your in/decrease the quantity amount or adds an item to the basket.
How to speed it up? Do you use React's "useOptimistic" hook or is there a better way? Any example of this would be greatly appreciated.
I am using the next-safe-action. Of course you can create with that safe-actions, but that's not the point of this message. They also provide a hook called
You can see it here: https://next-safe-action.dev/docs/usage-from-client/hooks/useoptimisticaction
useOptimisticAction that is way simpler then the react hook. I like to use it ^^You can see it here: https://next-safe-action.dev/docs/usage-from-client/hooks/useoptimisticaction
@Transvaal lion solved?