can you make a js Set, a state in svelte #17540
Replies: 2 comments
-
|
nevermind, found built in solution, SvelteSet |
Beta Was this translation helpful? Give feedback.
-
|
Yeah, the standard The simplest fix is to use Svelte's built-in import { SvelteSet } from 'svelte/reactivity';
let set = new SvelteSet(['a', 'b']);
// This will now trigger UI updates automatically
function add(val: string) {
set.add(val);
}If you really want to stick to a native let set = $state(new Set<string>());
// You have to trigger an assignment
function add(val: string) {
set.add(val);
set = new Set(set);
}Stick with |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
something like this : playground
it doesn't work but is there a way to make it work
Beta Was this translation helpful? Give feedback.
All reactions