how using createRoot?
I am developing a multi-language configuration for my program. I have implemented it in the following way so that it can be called inside the component or in some modules. (If I use context, I can't use it outside the component)
However, I get such a warning in the browser console and I'm not sure if such a warning has any positive negative effect.
"menus.tsx:10
computations created outside a
createRoot
or render
will never be disposed"
Please teach me, thank you!
3 Replies
if u do not use ssr and u don't want to dispose those memos/effects/stores you can safely ignore those warnings.
when an effect/signal is declared inside an effect solidjs can dispose them whenever the effect is ran again, but when effects/signals are declared outside any effects solidjs can not do that.
if you would like to dispose of the signals/effects yourself you can use
createRoot
, it passes a dispose function in its callback:
thanks. but I not sure whether my way of implementing global i18n through createRoot is correct. Is there a more appropriate way in the field of solidjs?
Your code is syntactically correct 👍
You are not making use of the dispose-callback, so you are not making use of the main reason why you would want to use
createRoot
, besides suppressing the error.
Also important to note: if you are using SSR this pattern (it's called a singleton
i think: having a reactive value that you import wherever you need it) will cause issues.
With SSR you should do dependency injection with context to not create accidental shared state between different visitors.