leptos-rs / book

The home for the Leptos book, which can be found deployed at https://book.leptos.dev
MIT License
80 stars 60 forks source link

Add part about `on_cleanup` #43

Closed tyoeer closed 5 months ago

tyoeer commented 9 months ago

on_cleanup is never mentioned, yet needed when dealing with for example set_timeout/set_interval. Their callback still gets run after navigating to a different page, even though any resources it accesses no longer exist, leading to an error. This can only be prevented by clearing them in on_cleanup.

diversable commented 8 months ago

Thanks for pointing this out. Do you have a suggestion for where we should cover that in the book?

tyoeer commented 8 months ago

Somewhere next to create_effect seems the most sensible to me. They're both part of the interaction between the reactive system and the non-reactive world.

gbj commented 5 months ago

Done in 20d7685a740093ec0df7a12208f7a6055e14856d