The closure passed to effect may return a cleanup function. This cleanup function will be run before each update. This is similar to the way useEffect() allows for cleanup between renders.
Effect returns a dispose function which may be called to "turn off" the effect forever.
Note it is not typically necessary to dispose an effect, so in most cases you can ignore the returned dispose function. Since effects only react to the signals they reference, and clean up after themselves, you can simply stop referencing a signal to stop reacting (e.g. using a boolean signal and if statement to turn on/off an effect). However, the returned dispose function can be useful when an effect's lifecycle is tied to the lifecycle of a component or class, and that component or class has a destructor.
This PR modifies effect in two non-breaking ways:
useEffect()
allows for cleanup between renders.Effect returns a dispose function which may be called to "turn off" the effect forever.
Note it is not typically necessary to dispose an effect, so in most cases you can ignore the returned dispose function. Since effects only react to the signals they reference, and clean up after themselves, you can simply stop referencing a signal to stop reacting (e.g. using a boolean signal and if statement to turn on/off an effect). However, the returned dispose function can be useful when an effect's lifecycle is tied to the lifecycle of a component or class, and that component or class has a destructor.