79727100

Date: 2025-08-06 09:43:19
Score: 0.5
Natty:
Report link

When using event handlers in server components, you cannot directly invoke a server action with props. Instead, you need to bind the server action to the props first. This ensures the props are prehydrated.

So instead of doing this

import { serverFunction } from "@/actions";

return(
  <button onClick={() => serverFunction(props)}>
    Action
  </button>
)

You would do this

import { serverAction } from "@/actions";

const serverFunctionAction = serverFunction.bind(null, props);

return(
  <button onClick={serverFunctionAction}>
    Action
  </button>
)

This creates a new function that can safely be used as an event handler without directly invoking the server action during render.

Read more about this: Docs

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Starts with a question (0.5): When
  • Low reputation (1):
Posted by: Paul Pietzko