Closed
Description
Sometimes it's good to have a watch that will react on change only once. I've made a function for this:
export const watchOnce = <T>(
target: WatchTarget<T>,
cb: (res: T, prev?: T) => any
) => {
const unwatch = watch(target, (res, prev?: T) => {
unwatch();
cb(res, prev);
});
return unwatch;
}
It returns a function to disable the watch manually.
WDYT?
Metadata
Metadata
Assignees
Labels
No labels