Prechádzať zdrojové kódy

chore: Clean up `use_on_destroy` docs (#2199)

* chore: Clean up `use_on_destroy` docs

* fmt
Marc Espin 1 rok pred
rodič
commit
7949fcda9a

+ 0 - 3
packages/hooks/src/lib.rs

@@ -84,9 +84,6 @@ pub use use_effect::*;
 mod use_memo;
 pub use use_memo::*;
 
-// mod use_on_create;
-// pub use use_on_create::*;
-
 mod use_root_context;
 pub use use_root_context::*;
 

+ 0 - 27
packages/hooks/src/use_on_create.rs

@@ -1,27 +0,0 @@
-use dioxus_core::ScopeState;
-use std::cell::Cell;
-use std::future::Future;
-
-/// A hook that runs a future when the component is mounted.
-///
-/// This is just [`use_effect`](crate::use_effect), but with no dependencies.
-/// If you have no dependencies, it's recommended to use this, not just because it's more readable,
-/// but also because it's a tiny bit more efficient.
-pub fn use_on_create<T, F>(future: impl FnOnce() -> F)
-where
-    T: 'static,
-    F: Future<Output = T> + 'static,
-{
-    let needs_regen = cx.use_hook(|| Cell::new(true));
-
-    if needs_regen.get() {
-        // We don't need regen anymore
-        needs_regen.set(false);
-
-        let fut = future();
-
-        cx.push_future(async move {
-            fut.await;
-        });
-    }
-}

+ 1 - 5
packages/hooks/src/use_on_destroy.rs

@@ -1,10 +1,6 @@
 use dioxus_core::prelude::use_drop;
 
-#[deprecated(
-    note = "Use `use_on_destroy` instead, which has the same functionality. \
-This is deprecated because of the introduction of `use_on_create` which is better mirrored by `use_on_destroy`. \
-The reason why `use_on_create` is not `use_on_mount` is because of potential confusion with `dioxus::events::onmounted`."
-)]
+#[deprecated(note = "Use `use_drop` instead, which has the same functionality.")]
 pub fn use_on_unmount<D: FnOnce() + 'static>(destroy: D) {
     use_drop(destroy);
 }