Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

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

💊 Valtio makes proxy-state simple for React and Vanilla
Go to Latest
function watch
import { watch } from "https://deno.land/x/valtio@v2.0.0-beta.3/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.