S
SolidJS3y ago
baxuz

disposing of a `createRoot` nested inside a `createEffect`?

I am creating a nested effect, like:
createEffect(() => {
// create nested effect
createRoot(() => {
createEffect(() => {
// ...
createEffect(() => {
// create nested effect
createRoot(() => {
createEffect(() => {
// ...
Will the root be automatically disposed when the scope of the first createEffect gets disposed? How can I inspect that?
6 Replies
thetarnav
thetarnav3y ago
1. roots won't ever be disposed manually - you control the disposal 2. not passing a parameter for the dispose function will actually create a "top-level" (unowned) root that doesn't have access to the context - creates it's own tree 3. you can use solid-devtools to see roots, where they are and when they are disposed
baxuz
baxuzOP3y ago
what's the dispose function?
thetarnav
thetarnav3y ago
createRoot(dispose => { dispose() })
baxuz
baxuzOP3y ago
Oh thanks a lot! It's really obscure. How come it's not returned as a value on createroot? The scope seems kinda weird
thetarnav
thetarnav3y ago
You can return anything from root, including the dispose function
baxuz
baxuzOP3y ago
oh. I... Did not know that.

Did you find this page helpful?