what should i do to make derived variables in svelte?

Use a derived store:

export const custom_items = writable([]);
export const another_items = writable([]);

const get_total = items => items.flat().map(x => x.amount).reduce((t, x) => t + x, 0)
    
export const total = derived(
  [custom_items, another_items], // deps
  items => get_total(items)      // [...values] => derived_value
)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top