Skip to main content
Module

x/valtio/docs/api/utils/subscribeKey.mdx

πŸ’Š Valtio makes proxy-state simple for React and Vanilla
Go to Latest
File
---title: 'subscribeKey'section: 'API'subSection: 'Utils'description: ''---
# subscribeKey
To subscribe to a primitive value in proxy state, consider `subscribeKey`.
```jsimport { 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
https://codesandbox.io/s/dynamic-ui-with-valtio-9gme46?file=/src/ComplexCounter.tsx