Created
March 24, 2025 09:11
-
-
Save tobySolutions/41e4164efb485e7cbd6e022542f0962c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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