Skip to content

Instantly share code, notes, and snippets.

@nickmccurdy
Last active July 21, 2023 06:45
Show Gist options
  • Save nickmccurdy/3c7bf45621a0edc6ac7ec3f2941dd076 to your computer and use it in GitHub Desktop.
Save nickmccurdy/3c7bf45621a0edc6ac7ec3f2941dd076 to your computer and use it in GitHub Desktop.
RSC render JSX using server action from client component
"use server";
export async function hello() {
return <h1>Hello, world!</h1>;
}
"use client";
import { ReactNode, useEffect, useState } from "react";
import { hello } from "./actions";
export default function Home() {
const [jsx, setJsx] = useState<ReactNode>();
useEffect(() => setJsx(hello()), []);
return jsx;
}
@riyaadh-abrahams
Copy link

useEffect is what I was missing. I was getting an infinite loop without it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment