useTask$()
使用 useTask$()
在初始渲染之前以及跟踪值发生变化时执行函数。该函数在渲染之前执行,但不能延迟渲染,因此如果 useTask$()
是异步的,则渲染将在 useTask$()
完全执行之前发生。
跟踪存储更改
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.