Created
September 25, 2024 17:37
-
-
Save ysmood/5356fe3a5876c4b2b2b66edec3dc5a85 to your computer and use it in GitHub Desktop.
next.js app mode doesn't allow useSyncExternalStore on server component
This file contains 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
import { useSyncExternalStore } from "react"; | |
let count = 0; | |
export default function Home() { | |
const c = useSyncExternalStore( | |
(cb) => { | |
const tmr = setInterval(() => { | |
count++; | |
cb(); | |
}, 1000); | |
return () => { | |
clearInterval(tmr); | |
}; | |
}, | |
() => count, | |
() => count | |
); | |
return ( | |
<> | |
<h3>Count: {c}</h3> | |
</> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment