-
I have a class like this: import { proxy, ref } from 'valtio'
class TreeNode {
expanded = false
#children = ref({})
toggle() {
this.expanded = !this.expanded
}
getOrCreate(id: string) {
if (id in this.#children) {
return this.#children[id]
} else {
const node = proxy(new TreeNode())
return (this.#children[id] = node)
}
}
// Want to make this getter a ref, but how?
get childrenLength() {
Object.keys(this.#children).length
}
}
export const rootNode = proxy(new TreeNode()) and want to exclude |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I don't think it's possible or extremely hard. |
Beta Was this translation helpful? Give feedback.
-
Actually, there's no need to exclude a class field or getter from proxy. Because if I don't want my component to react on a field or computed value changes I can just use |
Beta Was this translation helpful? Give feedback.
Yes.
See: https://github.com/pmndrs/valtio/blob/26caa885050b5c9ac8c80c90e216599936e925f8/docs/how-tos/how-to-avoid-rerenders-manually.mdx