Use useTask$() to execute a function before the initial render and whenever the tracking values change. The function executes before rendering, but it can't delay rendering, so if useTask$() is asynchronous, the rendering will happen before the useTask$() is fully executed.

Tracking store changes

The useTask$() hook receives a track() function used for setting up subscriptions that will automatically rerun the useTask$() hook. The set of track() properties resets on each useTask$() execution, therefore it is important to always use track() to set up subscriptions anew. Because of this it is possible for the useTask$() to subscribe to different properties over time.


The useTask$() hook can return a cleanup callback. This is useful for cleaning up any resources before new execution.


Edit Tutorial