Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/valtio/src/vanilla/utils/watch.ts>watch

🧙 Valtio makes proxy-state simple for React and Vanilla
Latest
function watch
import { watch } from "https://deno.land/x/valtio@v2.1.1/src/vanilla/utils/watch.ts";

watch

Creates a reactive effect that automatically tracks proxy objects and reevaluates everytime one of the tracked proxy objects updates. It returns a cleanup function to stop the reactive effect from reevaluating.

Callback is invoked immediately to detect the tracked objects.

Callback passed to watch receives a get function that "tracks" the passed proxy object.

Watch callbacks may return an optional cleanup function, which is evaluated whenever the callback reevaluates or when the cleanup function returned by watch is evaluated.

watch calls inside watch are also automatically tracked and cleaned up whenever the parent watch reevaluates.

Parameters

callback: WatchCallback
optional
options: WatchOptions

Returns

Cleanup

A cleanup function that stops the callback from reevaluating and also performs cleanups registered into watch.