Skip to content

Usage with button on RSC #10836

Answered by decovicdev
ScreamZ asked this question in Help
May 6, 2024 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

@ScreamZ they said

You can invoke a Server Action from event handlers such as onClick.

fix 1 RCC

 "use server";
 
export const signInAction = async () => {
            await signIn();
}
 "use client";

import { signInAction } from "actions.js"


<button  onClick={signInAction}></button>

fix 2 RSC

<button
        formAction={async () => {
          "use server";
          await signIn();
        }}
      ></button>
  • you can't create actions in client components
  • you can't use onClick on server components

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@ScreamZ
Comment options

@ScreamZ
Comment options

Answer selected by ScreamZ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants