Skip to content

Instantly share code, notes, and snippets.

@tobySolutions
Created March 24, 2025 09:11
Show Gist options
  • Save tobySolutions/41e4164efb485e7cbd6e022542f0962c to your computer and use it in GitHub Desktop.
Save tobySolutions/41e4164efb485e7cbd6e022542f0962c to your computer and use it in GitHub Desktop.
// RSC to fetch initial data
export default async function CounterRSC() {
const initialCount = 0; // Or fetch from a database
return (
<CounterClient initialCount={initialCount} />
);
}
// new file
'use client' // Indicate that this is a client component
import { useState } from 'react';
export default function CounterClient({ initialCount }) {
const [count, setCount] = useState(initialCount);
const increment = () => {
setCount(count + 1);
};
return (
<div>
<p>Count: {count}</p>
<button onClick={increment}>Increment</button>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment