The function to track and reactively execute.
Optional
updates: Map<string, UpdateDataRecord>Optional
options: { The options for the autorun function.
The number of milliseconds to delay the execution of the callback function.
An optional name for the autorun.
An optional function to handle errors.
An optional AbortSignal to cancel the autorun.
A function that can be called to unsubscribe the callback function from changes in the tracked dependencies.
const a = atom(0, { name: "a" });
const b = atom(0, { name: "b" });
let foo = 0;
autorun(() => {
a.value;
b.value;
foo++;
});
console.log(a.value, b.value, foo); // 0 0 1
a.value++;
console.log(a.value, b.value, foo); // 1 0 2
b.value++;
console.log(a.value, b.value, foo); // 1 1 3
batch(() => {
a.value++;
b.value++;
});
console.log(a.value, b.value, foo); // 2 2 4
Automatically tracks and subscribes to changes in reactive items used by the specified function. This allows the function to be re-executed whenever any of its dependencies change, maintaining up-to-date results.