div(derive(() =>
vs derive(() => div
: Which is "better"?
#457
-
Although both components are visually identical, is there some "best practice" that favours a particular implementation? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
A will only change the
Edit: In general, you will not need to use |
Beta Was this translation helpful? Give feedback.
-
You can also refer to |
Beta Was this translation helpful? Give feedback.
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 thetags
functions of VanJS. When a function appears in attribute or content position, it will automatically be wrapped in a derive.