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

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

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

subscribeKey

The subscribeKey utility enables subscription to a primitive subproperty of a given state proxy. Subscriptions created with subscribeKey will only fire when the specified property changes. notifyInSync: same as the parameter to subscribe(); true disables batching of subscriptions.

Examples

import { subscribeKey } from 'valtio/utils' subscribeKey(state, 'count', (v) => console.log('state.count has changed to', v))

Type Parameters

T extends object
K extends keyof T

Parameters

proxyObject: T
key: K
callback: (value: T[K]) => void
optional
notifyInSync: boolean

Returns

() => void