Skip to content

Component guide - How to create components with reactive attributes in an idiomatic vanjs way #23

Answered by Tao-VanJS
iongion asked this question in Q&A
Discussion options

You must be logged in to vote

What if one wants to create a custom attribute that is not style but for example data-icon in a fictive Icon component ?

Custom attributes of native DOM elements are supported in the same way as properties. When the field of props arg doesn't exist as an element property, VanJS will set the prop value as a DOM attribute. This behavior is discussed at https://vanjs.org/advanced#dom-attributes-vs-properties

What if one wants to create a reactive isOpen boolean attribute for a fictive popup / modal / collapsible ?

For custom components (which is just a plain JavaScript function), there is no builtin support for state-derived properties, although you can provide similar support in the imp…

Replies: 1 comment 13 replies

Comment options

You must be logged in to vote
13 replies
@iongion
Comment options

@Tao-VanJS
Comment options

@Tao-VanJS
Comment options

@Tao-VanJS
Comment options

@efpage
Comment options

Answer selected by Tao-VanJS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants