Quick start
This guide will walk you through creating your first page with COSMOS RSC, demonstrating React Server Components, streaming, and server actions.Create your first page
Create a new page file
Create a new file in the This page is now available at
app/pages/ directory. The filename determines the route.app/pages/hello.js
/hello. By default, all components are Server Components.Add async data fetching
Server Components can be async and fetch data directly without useEffect or separate API routes.
app/pages/hello.js
Server Components can directly access databases, file systems, and server-side APIs without exposing sensitive data to the client.
Use server-only APIs
Import server-only utilities like cookies directly in your Server Components.
app/pages/hello.js
Add streaming with Suspense
Use React Suspense to stream components progressively as data becomes available.
app/pages/hello.js
Each Suspense boundary streams independently, showing loading states until data is ready.
Create a server action
Server actions handle form submissions without needing API endpoints.Create a new file for your server actions:
app/actions/my-actions.js
Create a form with server action
Use your server action in a form. You can also create a client component for enhanced UX.First, create a submit button component:Then use it in your page:
app/components/submit-button.js
app/pages/contact.js
The
SubmitButton uses 'use client' to access React hooks like useFormStatus, while the form and page remain Server Components.Next steps
Now that you’ve created your first pages, explore more features:Routing
Learn about file-system based routing and navigation
Server Components
Deep dive into React Server Components
Server Actions
Master server actions for forms and mutations
Styling
Customize your application with Tailwind CSS