Repository navigation
bind + memoize? #68
Answered
by
Tao-VanJS
benallfree
asked this question in
Q&A
|
I have a state object with deep nesting, and certain components only rely on certain paths in the object. Do you have suggestions for this situation? edit: I know state vars cannot be nested, and I'm looking for a way to tell |
Answered by
Tao-VanJS
Jul 10, 2023
Replies: 1 comment 5 replies
|
In idiomatic VanJS code, we recommend defining states at the leaf-level of the global state object, which means instead of having: const s = van.state({
a: 1,
b: 2,
})you can have: const s = {
a: van.state(1),
b: van.state(2),
}This way you will have the ability to bind smaller components to each individual field path. |
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Alternatively, you can use
Object.assignto do field-level state updates, something like:Note that the states won't be considered changed if their underlying values remain the same.
You can define your custom deep assignment functions if you need to.