-
There is an example on VanJS.org about State object as properties, which is a bit confusing: const {input, span} = van.tags
const ConnectedProps = () => {
const value = van.state("")
return span(
input({type: "text", value, oninput: e => value.val = e.target.value}),
input({type: "text", value, oninput: e => value.val = e.target.value}),
)
}
van.add(document.body, ConnectedProps()) This works, but if you rename the state object, it does not: const ConnectedProps = () => {
const text = van.state("")
return span(
input({type: "text", text, oninput: e => text.val = e.target.value}),
input({type: "text", text, oninput: e => text.val = e.target.value}),
)
} Here, you need to use: input({type: "text", value: text, oninput: e => text.val = e.target.value}),
} I have no clue why a variable name can be used as an attribute name in VanJS. Maybe it is a nice feature, but is it in any case not self-explanatory. The example would be much clearer, if the value-attribute was named explicitpy. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
This is standard JavaScript feature called property value shorthand. Here is an article that explains the feature: https://www.geeksforgeeks.org/shorthand-syntax-for-object-property-value-in-es6/. Basically |
Beta Was this translation helpful? Give feedback.
This is standard JavaScript feature called property value shorthand. Here is an article that explains the feature: https://www.geeksforgeeks.org/shorthand-syntax-for-object-property-value-in-es6/.
Basically
{value}
is just a shorthand-way to say{value: value}
.