S
SolidJS16mo ago
Revxrsal

onCleanup in Root component?

o/ so i have this component in my root. if i refresh the page, it doesn't log the cleaning up root!! message. is there any other way to run code when the app stops/refreshes?
onCleanup(() => {
console.log("cleaning up root!!")
})
onCleanup(() => {
console.log("cleaning up root!!")
})
3 Replies
Revxrsal
RevxrsalOP16mo ago
nvm, found i could do
window.addEventListener("beforeunload", () => {
...
}, false);
window.addEventListener("beforeunload", () => {
...
}, false);
but is onCleanup() just not going to work for roots?
Otonashi
Otonashi16mo ago
roots aren't disposed when the page unloads if you want to do that then you could probably do like
const dispose = render(() => <App />, document.getElementById("app"));
window.addEventListener("beforeunload", dispose);
const dispose = render(() => <App />, document.getElementById("app"));
window.addEventListener("beforeunload", dispose);
though i don't know if that's necessarily a good idea if there's a lot to clean up
Revxrsal
RevxrsalOP16mo ago
i just want to save something to localStorage i had it earier as a store and the localStorage was saved inside an effect, but since i update the data a lot (10+ times/s) i figured out that's a bit inefficient
Want results from more Discord servers?
Add your server