improve use_drop documentation (#3023)
This commit is contained in:
1 parent
d1c84d9a25
commit
d0c9b6712d
1 file changed
+9
-3
@@ -310,6 +310,9 @@ pub fn schedule_update_any() -> Arc<dyn Fn(ScopeId) + Send + Sync> {
|
|||||||
/// This can be used to clean up side effects from the component
|
/// This can be used to clean up side effects from the component
|
||||||
/// (created with [`use_effect`](dioxus::prelude::use_effect)).
|
/// (created with [`use_effect`](dioxus::prelude::use_effect)).
|
||||||
///
|
///
|
||||||
|
/// Note:
|
||||||
|
/// Effects do not run on the server, but use_drop **DOES**. It runs any time the component is dropped including during SSR rendering on the server. If your clean up logic targets web, the logic has to be gated by a feature, see the below example for details.
|
||||||
|
///
|
||||||
/// Example:
|
/// Example:
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use dioxus::prelude::*;
|
/// use dioxus::prelude::*;
|
||||||
@@ -346,9 +349,12 @@ pub fn schedule_update_any() -> Arc<dyn Fn(ScopeId) + Send + Sync> {
|
|||||||
/// });
|
/// });
|
||||||
///
|
///
|
||||||
/// use_drop(move || {
|
/// use_drop(move || {
|
||||||
/// /// restore scroll to the top of the page
|
/// // This only make sense to web and hence the `web!` macro
|
||||||
/// let window = web_sys::window().unwrap();
|
/// web! {
|
||||||
/// window.scroll_with_x_and_y(original_scroll_position(), 0.0);
|
/// /// restore scroll to the top of the page
|
||||||
|
/// let window = web_sys::window().unwrap();
|
||||||
|
/// window.scroll_with_x_and_y(original_scroll_position(), 0.0);
|
||||||
|
/// }
|
||||||
/// });
|
/// });
|
||||||
///
|
///
|
||||||
/// rsx! {
|
/// rsx! {
|
||||||
|
|||||||
Reference in new issue
Block a user