Skip to content

div(derive(() => vs derive(() => div: Which is "better"? #457

Answered by bleistivt
bobinspace asked this question in Q&A
Discussion options

You must be logged in to vote

A will only change the Text Node contained in the div, when the state changes, B will recreate the div, so A is preferable. It could also just be rewritten as:

const A = () => div(() => state.val ? 1 : 0);

Edit: In general, you will not need to use derive very much when dealing with the tags functions of VanJS. When a function appears in attribute or content position, it will automatically be wrapped in a derive.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@bobinspace
Comment options

Answer selected by bobinspace
Comment options

You must be logged in to vote
0 replies
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