Menu
Coddy logo textTech

Recap: Server Actions

Part of the Next.js Essentials section of Coddy's React journey — lesson 33 of 47.

challenge icon

Challenge

Medium

Chapter recap: the guestbook below saves nothing and never updates. Build the whole flow: form → action → fresh page.

  1. In app/actions.js, mark the file with 'use server' as its first line, and after the save call revalidatePath('/') (imported from 'next/cache').
  2. In app/page.jsx, import addGuest from './actions' and wrap the input and button in a <form> with id="guest-form" and action={addGuest}.
  3. Give the input name="name": that's the key the action reads with formData.get('name').

Try it yourself

import './globals.css';

export const metadata = {
    title: 'My App',
};

export default function RootLayout({ children }) {
    return (
        <html lang="en">
            <body>
                {children}
            </body>
        </html>
    );
}

All lessons in Next.js Essentials