S
SolidJS2y 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
thetarnav2y 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
baxuz2y ago
what's the dispose function?
thetarnav
thetarnav2y ago
createRoot(dispose => { dispose() })
baxuz
baxuz2y 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
thetarnav2y ago
You can return anything from root, including the dispose function
baxuz
baxuz2y ago
oh. I... Did not know that.
Want results from more Discord servers?
Add your server
More Posts