The effect function is the last piece that makes everything reactive. When you access a signal inside its callback function, that signal and every dependency of said signal will be activated and subscribed to. In that regard it is very similar to computed(fn). By default all updates are lazy, so nothing will update until you access a signal inside effect.
You can destroy an effect and unsubscribe from all signals it was subscribed to, by calling the returned function.
Cleanup Callback
You can also return a cleanup function from an effect. This function will be called when the effect is destroyed.
On Dispose Callback
You can also pass a callback to effect that will be called when the effect is destroyed.
Warning About Cycles
Mutating a signal inside an effect will cause an infinite loop, because the effect will be triggered again. To prevent this, you can use untracked(fn) to read a signal without subscribing to it.