div(derive(() => vs derive(() => div: Which is "better"?
#457
Answered
by
bleistivt
bobinspace
asked this question in
Q&A
Although both components are visually identical, is there some "best practice" that favours a particular implementation? |
Answered by
bleistivt
Jul 12, 2025
Replies: 2 comments 1 reply
|
A will only change the
Edit: In general, you will not need to use |
1 reply
Answer selected by
bobinspace
|
You can also refer to |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A will only change the
TextNode 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
derivevery much when dealing with thetagsfunctions of VanJS. When a function appears in attribute or content position, it will automatically be wrapped in a derive.