useTask$()

Use useTask$() to execute a function before the initial render and whenever the tracking values change. The function executes before rendering. If useTask$() is asynchronous, the rendering will be blocked until 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.

Cleanup

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

Example

Edit Tutorial