Streaming Component via Server Action

Yes you read it right, we can stream components from server actions and with NextJs is pretty straight forward.

This is a Next.js project bootstrapped with create-next-app.

Getting Started

First, run the development server:

npm run dev # or yarn dev # or pnpm dev # or bun dev

Open http://localhost:3000 with your browser to see the result.

Streaming Component via Server Action

export async function addPerson(data) { return { ui: ( <div id="streamed component"> <Hello /> // Pure Static component <Counter /> // Use useState </div> ), }; }
Error: Could not find the module "\stream-components-server-action\src\app\_components\counter.jsx#default" in the React Client Manifest. This is probably a bug in the React Server Components bundler.
export async function addPerson(data) { return { ui: ( <div id="streamed component"> <Hello /> // Pure Static component </div> ), }; }

![(UI)](./public/stream-comp.png)

- This is a simple example, but I have used this in my [portfolio](https://cdasauni.com) to Stream a Component that I create after the LLM response and then mutate it to add an interactive button to it.
  ![(UI)](./public/portfolio.png)