How to call a server action without a form? #54699
Unanswered
nareshbhatia
asked this question in
App Router
Replies: 1 comment 3 replies
-
Hi @nareshbhatia,
When the user clicks on the button, the updateFavorite() function will be called, which will make a PATCH request to the server to update the favorite status of the movie. The revalidatePath() function will then be called to invalidate the cache for the /movie-magic-rsc route, so that the browser will fetch the latest data from the server. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a Server Component that uses a Server Action to toggle the favorite status of a movie. See below:
I have made this work using a form - I have to click on the heart icon (that works like a checkbox) and then click on the submit button. However that's not a great user interface. How can I do this without clicking on the submit button? I can think of removing the checkbox from the form and using the
onClick()
event to call the server action, but that would force me to make the component a client component. What's the best way to do this?Here's my repo and the relevant code pasted below:
Beta Was this translation helpful? Give feedback.
All reactions