How to call a server action without a form? #54699
Replies: 2 comments 5 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.
-
Hi @nareshbhatia, I am reading this discussion in 2025! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
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