Skip to content

use class in state #15043

Answered by brunnerh
APerricone asked this question in Q&A
Jan 17, 2025 · 2 comments · 2 replies
Discussion options

You must be logged in to vote

You can wrap the object and assign a new one on change. E.g.

let stateClass = $state({ counter: new ValueCnt() });
stateClass.counter.value += 1;
stateClass = { ...stateClass }; // force reactivity via new object

Playground

See also this issue:

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@APerricone
Comment options

Comment options

You must be logged in to vote
1 reply
@APerricone
Comment options

Answer selected by APerricone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants