Svelte exposes a derived
function to create derived stores.
The first argument in derived
is an existing store. The second is a function that calculates the derived data from the current store value.
import { writable, derived } from 'svelte/store';
export const todos = writable([]);
export const completedTodos = derived(
todos,
($todos) => {
return $todos.filter((todo) => todo.completed),
},
);