untracked<T> method
T
untracked<T>(
- T callback()
inherited
Executes the given callback
function without tracking any state changes.
This means that any state changes that occur inside the callback
function
will not trigger any side effects.
The callback
function should return a value of type T
.
The returned value will be the result of the untracked operation.
Example usage:
final state = UseState(0);
final computed = UseCompute(() => state.value + 1, [state]);
Rt.untracked(() {
state.value = 2;
print(computed.value); // 1 -> because the state change is not tracked
});
print(computed.value); // 1 -> because the state change is not tracked
Implementation
T untracked<T>(T Function() callback) {
if (_isUntrackedRunning) {
return callback();
}
try {
_isUntrackedRunning = true;
return callback();
} finally {
_isUntrackedRunning = false;
}
}