Skip to content

Can I create stores out of component and use it in components? #675

Answered by ryansolid
weijarz asked this question in Q&A
Discussion options

You must be logged in to vote

Yes. The important thing to know is that roots can be disposed of. If it's truly a singleton then it probably doesn't matter. But if you ever need to dispose a root it's the function passed to the first argument of createRoot.. You can always hoist it out:

let dispose;
createRoot((d) => {
  dispose = d;
  // reactive stuff
});

// somewhere else when you want to clean up.
dispose();

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by weijarz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants