-
. |
Beta Was this translation helpful? Give feedback.
Answered by
dai-shi
Jun 14, 2022
Replies: 1 comment 1 reply
-
In general, I would suggest to avoid the need of checking if an object is a proxy at runtime. You can't call import { proxy } from 'valtio'
const IS_PROXY = Symbol()
const state = proxy({
// ...
[IS_PROXY]: true,
})
const isProxy = (obj) => obj[IS_PROXY] === true For hacks and probably for 3rd-party libraries, this is possible: import { getVersion } from 'valtio'
const isValtioProxy = (obj) => typeof getVersion(obj) === 'number' |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
aelbore
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In general, I would suggest to avoid the need of checking if an object is a proxy at runtime. You can't call
useSnapshot
conditionally anyway.If you need dynamic coding style, you want to have such a property on your end.
For hacks and probably for 3rd-party libraries, this is possible: