Skip to content

Instantly share code, notes, and snippets.

@ysmood
Created September 25, 2024 17:37
Show Gist options
  • Save ysmood/5356fe3a5876c4b2b2b66edec3dc5a85 to your computer and use it in GitHub Desktop.
Save ysmood/5356fe3a5876c4b2b2b66edec3dc5a85 to your computer and use it in GitHub Desktop.
next.js app mode doesn't allow useSyncExternalStore on server component
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