Skip to main content
Module

x/valtio/docs/utils/derive.mdx

πŸ’Š Valtio makes proxy-state simple for React and Vanilla
Go to Latest
File
---title: 'derive'section: 'Utils'description: 'create a new proxy derived from others'---
# derive
#### create a new proxy derived from others
You can subscribe to some proxies using `get` to create snapshots used to compute new values.
```jsimport { derive } from 'valtio/utils'
// create a base proxyconst state = proxy({ count: 1,})
// create a derived proxyconst derived = derive({ doubled: (get) => get(state).count * 2,})
// alternatively, attach derived properties to an existing proxyderive( { tripled: (get) => get(state).count * 3, }, { proxy: state, })```
# underive
#### stop evaluating
In some cases you may want to unsubscribe after deriving a proxy. To do so, use the `underive` util. You may also pass keys to indicate which properties you want to unsubscribe. If you specify `delete` option, it will delete the propertiesand you can attach new derived properties.
```jsimport { derive, underive } from 'valtio/utils'const state = proxy({ count: 1,})
const derivedState = derive({ doubled: (get) => get(state).count * 2,})
underive(derivedState)```