From the course: React Essential Training
Unlock this course with a free trial
Join today to access over 24,800 courses taught by industry experts.
Creating a server action - React.js Tutorial
From the course: React Essential Training
Creating a server action
- [Instructor] We've created a little container for our form so we have an email and a message. Now we need to handle these form elements when they are submitted. So I want to show you how you can work with server actions. Server actions are functions that can be executed on the server. These can be called from server components or client components to do things like handling form submissions and other types of data mutations. So we're going to put all of this directly into the same file so that we can see how everything works together. The first thing I'll do is here in contact page.js, we're going to create an asynchronous function called submitForm. You can call this function whatever you want to call it, something descriptive. Obviously the more descriptive the better. Then we're going to use formData. So whenever I'm dealing with form elements, our browser is going to process those form elements so we can just work with those elements natively instead of having to create…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.