once<T> method
Watcher<T>
once<T>(
- SourcesFn<
T> sourcesFn, - WatcherFn<
T> fn, { - WhenFn<
T> ? when, - JoltDebugOption? debug,
Creates a watcher hook that executes only once.
Parameters:
sourcesFn: Function that returns the values to watchfn: Callback function executed when sources changewhen: Optional condition function for custom trigger logicdebug: Optional debug options
Returns: A Watcher that executes only once
Implementation
@defineHook
Watcher<T> once<T>(
SourcesFn<T> sourcesFn,
WatcherFn<T> fn, {
WhenFn<T>? when,
JoltDebugOption? debug,
}) {
late _UseWatcherHook<T> hook;
hook = _UseWatcherHook<T>(sourcesFn, (newValue, oldValue) {
fn(newValue, oldValue);
hook.state.dispose();
}, when: when, immediately: false, debug: debug);
return useHook(hook);
}