1. API
  2. subscribeKey

subscribeKey

To subscribe to a primitive value in proxy state, consider subscribeKey.

import { subscribeKey } from 'valtio/utils'

const state = proxy({ count: 0, text: 'hello' })
subscribeKey(state, 'count', (v) =>
  console.log('state.count has changed to', v)
)

Codesandbox demo