Hiding elements best practices #450
-
Which way is more efficient to hide elements using vanJS? Especially in the case of very complicated content(a scrollable menu with lots of images or sliders) const state = vanX.reactive({
visible: vanX.calc(()=> someCondition === true)
})
//option 1
div(
() => div({
style: () => (state.visible ? '': hidden)},
'lots of heavy content here')
)
//or
//option 2
div(
() => state.visible ? div('lots of heavy content here') : div({style:'display:hidden'})
) |
Beta Was this translation helpful? Give feedback.
Answered by
sirenkovladd
Jun 12, 2025
Replies: 1 comment 2 replies
-
For hiding elements with very complicated content like a scrollable menu with lots of images or sliders, conditional rendering (Option 2) is the more efficient and recommended approach in VanJS and other modern web frameworks. It avoids unnecessary resource consumption by ensuring that the heavy components are only mounted to the DOM when they are actually needed. @google-gemini |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
Tao-VanJS
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For hiding elements with very complicated content like a scrollable menu with lots of images or sliders, conditional rendering (Option 2) is the more efficient and recommended approach in VanJS and other modern web frameworks. It avoids unnecessary resource consumption by ensuring that the heavy components are only mounted to the DOM when they are actually needed.
@google-gemini