actions/
Server Actions for progressively-enhanced cart mutations.
"use server" functions — cart mutations that work with JavaScript
disabled, and pair with <OptimisticCart>'s useOptimistic for instant
feedback when JS is available. This pairing (Server Action + optional
client-side optimism) is the actual "feels native to Next.js"
differentiator over mirroring a browser SDK's hook shape.
import { addToCartAction, updateCartItemAction, removeCartItemAction, clearCartAction } from "@prebit/boron/actions";addToCartAction
<form action={addToCartAction}>
<input type="hidden" name="productId" value={product.id} />
<input type="hidden" name="variantId" value={selectedVariant?.id ?? ""} />
<button type="submit">Add to cart</button>
</form>A bare form action prop needs a void-returning wrapper
addToCartAction returns the updated Cart (useful for programmatic
callers like <OptimisticCart>), but React's typing for a plain form's
action prop expects void | Promise<void>. Wrap it:
<form action={async (formData: FormData) => { "use server"; await addToCartAction(formData); }}>(see prebit-template-store's own product page for the working example).
Also callable directly (not just as a form action) with a typed input:
await addToCartAction({ productId, variantId, quantity: 1 });updateCartItemAction / removeCartItemAction / clearCartAction
Same shape — { itemId, quantity }, { itemId }, and no input
respectively. All three manage the cart token cookie via next/headers'
cookies(), using the exact same cookie name
client/'s useCart() uses — a token written by
one is read by the other.