createSingletonRoot shows cleanups created outside a `createRoot` or `render` will never be run
Hello,
I've been using Context to create singleton instances that are used through my solid.js app. (mostly for services that make GRPC calls).
It didn't exactly seem right to use Context for this. I saw createSingletonRoot which also allows me to create sharable singletons. Problem is I keep getting this warning when using createSingletonRoot.
cleanups created outside a
createRoot or
render will never be run
It sort of make sense since createSingletonRoot is outside of the main root.
What am I missing to make the warning go away? How do i cleanup a createSingletonRoot?
Thank you6 Replies
So far I see some benefits from using createSingletonRoot. Like simpler code vs context, and not having to worry about level specific provider since my singletons are truly global.
OK figured it out, problem is I was calling it outside
render
that makes sense. Works without the warning now.
Any opinions of Pros and Cons of using createSingletonRoot vs Context?You can also use
createRoot
directly if you just want to suppress the warning.
I love singletons, it's definitely my goto if I can. Just be aware that singletons should not be used if you are going to ssr, it could leak state between different sessions.thank you! good to know
@bigmistqke what is your personal preference for using
createRoot
vs using a context for singletons? Any pros or cons?My personal preference is:
context
- when I need state scoped to a specific branch in the jsx
- when I do ssr
singleton
- all the other situations
It's the path of least resistance imo
Makes sense. Thank you
ur very welcome!