Replies: 3 comments 5 replies
-
The For your example to be working, you can try something like this: const items = ...
const filteredItems = vanX.reactive([])
van.derive(() => vanX.replace(filteredItems, () => items.filter(item => item.period === state.period)))
vanX.list(..., filteredItems, ...) Hope it helps :-) |
Beta Was this translation helpful? Give feedback.
-
Thanks, is derive firing in infinite loop? const state = vanX.reactive({period: 'lifetime'})
const filteredItems = vanX.reactive([])
van.derive(() => vanX.replace(filteredItems, () => items.filter(item => item.period === state.period)))
return div({ style: 'margin:3rem;margin-top:auto;margin-bottom:auto;flex-direction:column;align-items:center;gap:3rem;}' },
// h1({ style: 'font-size:4rem;min-height:9rem' }, 'WEBBYPAINT PRO Pricing'),
div(
button({ onclick: () => state.period = 'lifetime' }, 'Lifetime'),
button({ onclick: () => state.period = 'monthly' }, 'Monthly'),
),
span({ style: 'font-size:2.5rem;margin:3rem;margin-bottom:4rem;text-align:center;' }, 'Unlock all features and tools. Pay once, use forever. Upgrade at any time'),
vanX.list(() => div({ class: 'pricingCards', style: 'place-items: center' }), filteredItems, ({ val: v }) =>
RangeError: Maximum call stack size exceeded
at set val (:1:461)
at V (:1:866)
at set val (:1:531)
at Object.T [as replace] (:1:1738)
at w (:1:218)
at V (:1:867)
at set val (:1:531)
at Object.T [as replace] (:1:1738)
``` |
Beta Was this translation helpful? Give feedback.
-
That works perfectly, thanks!! This is a pretty common situation in my app, should I always use this workaround or is there more standardized vanjs way to do it? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I am trying to filter an array of objects (items) using
items.filter(item => item.period === state.period)
but this code isn't working. Is there a way to do this with vanx.list?Beta Was this translation helpful? Give feedback.
All reactions