What problem does it solve?
This Skill addresses the common challenge in Next.js applications where client-side interactions (like button clicks or form submissions) need to trigger the setting or modification of server-side cookies, which is crucial for managing user sessions, preferences, and authentication states.
Core Features & Use Cases
- Client-Triggered Cookie Setting: Enables client components to initiate cookie modifications.
- Server Action Integration: Leverages Next.js Server Actions to securely set cookies on the server.
- Pattern for Authentication/Preferences: Ideal for implementing features like theme toggles, user preferences, or session management where client-side events must persist server-side state via cookies.
- Use Case: A user clicks a "Enable Dark Mode" button in a client component. This action calls a server action that sets a
theme=dark cookie, which the server then uses to render the page with dark mode styles.
Quick Start
Use the nextjs-client-cookie-pattern skill to implement a button in app/CookieButton.tsx that calls the setPreference server action from app/actions.ts to set a cookie.