The effect
function in Angular runs a callback when a signal value it depends on changes. The callback is also invoked when the component first renders.
An effect
can depend on multiple signals or computed signals. When any of these signals change, the effect
callback executes.
Instead of running effect
in the constructor, it's best to assign it to a component property. This allows for manual interaction with the EffectRef
if needed.