signals
signals copied to clipboard
effect is run during SSR (React version)
Having effect(() => console.log('hello')) in a component prints in the console of a Next.js project, so it's being run on the server.
Is it a bug? If not, how to use effect on the client-only? (which is what most people would want I think).
which is what most people would want I think
Depends on what you do with signals. I have a few small private projects/scripts which are node-only and don't require a framework. There effects need to fire.
That said we definitely need to provide a way to only run effects on the client. Need to think a bit more about this on how best to do that without requiring users to change their code.
A workaround for now is to instantiate effect() inside useEffect():
useEffect(() => {
const dispose = effect(() => ...)
return () => dispose();
}, [])