-
By intuition I tried this and is not working const { div, img, button } = van.tags;
const App = () => {
const isOpen = van.state(false);
const imgSrc = van.bind(isOpen, (v) => v ? "open-icon.png" : "close-icon.png");
return div(
{ class: "App" },
button({ onClick: () => isOpen.val = !isOpen.val; }),
img({ src: imgSrc })
} |
Beta Was this translation helpful? Give feedback.
Answered by
Tao-VanJS
May 26, 2023
Replies: 1 comment
-
Hi, Thanks for reaching out! The idiomatic solution for your use case is to use State-derived properties. Thus instead of having: const imgSrc = van.bind(isOpen, (v) => v ? "open-icon.png" : "close-icon.png"); you can have: const imgSrc = {deps: [isOpen], f: (v) => v ? "open-icon.png" : "close-icon.png"} This technique is illustrated in sample app JSON Inspector (code) and Textarea with Autocomplete (code). btw: I guess |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Tao-VanJS
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
Thanks for reaching out!
The idiomatic solution for your use case is to use State-derived properties. Thus instead of having:
you can have:
This technique is illustrated in sample app JSON Inspector (code) and Textarea with Autocomplete (code).
btw: I guess
onClick
should beonclick
which is a native property of DOM node.