My name is Aurora. I'm a web developer from Norway, and I work as a consultant in Oslo, and I'm building actively with React components in my project, and that's where I try to get my knowledge and make some examples to help teach other people about that.
How many people use React server components here? Okay, quite a lot. Wow, that's good, that's good. Nice.
I'm excited to be demoing a practical example of working with forms and server components here today, and I'm going to be coding something that is based on or inspired by a feature that I built in my current project. So let's get right to it.
So the setup here is an XGS app router course, and it's using Prisma as an ORM and a local database and Tailwind for CSS. I'm a huge Tailwind fan. And let's just go through the starting files here.
So since we're in the app router, everything is a server component by default, right? And that means that all of these components here are, wow, okay, are server components by default. And that means that I can actually make them async. So server components can be async, and I can actually asynchronously fetch data right inside the component itself.
And here I have a message box, and it's fetching messages from the database directly through Prisma. And then there is also a message display component here, or I'm mapping the messages to message display components. And here, all we need to do is just style based on whether the message is written by the user. So just a server component, nothing special here.
And there is also a message input, and that's this form here, and it doesn't do anything right now. It's just a form with a single input, and I'll just test it here. So nothing's going to happen.
So this is all server component, which means that there's no JS added to the client bundle for any of these components. And let's enhance this with React 19. The goal will be to make this interactive, while minimizing the JS on the client and reducing the front-end complexity. And let's begin by just making the form work. So I'm going to use React 19's extension of the form element to bind the action property to a function. This is we can do this with React 19 now.
And React 19 was just released like last week, two weeks ago, finally, after being RC for like half a year. So, whoo. Yeah, that's nice. Yeah.
Comments