chore: Clean up use_on_destroy docs (#2199)
* chore: Clean up `use_on_destroy` docs * fmt
This commit is contained in:
1 parent
57e05dcf3a
commit
7949fcda9a
3 files changed
+1
-35
No files matched your search
@@ -84,9 +84,6 @@ pub use use_effect::*;
|
|||||||
mod use_memo;
|
mod use_memo;
|
||||||
pub use use_memo::*;
|
pub use use_memo::*;
|
||||||
|
|
||||||
// mod use_on_create;
|
|
||||||
// pub use use_on_create::*;
|
|
||||||
|
|
||||||
mod use_root_context;
|
mod use_root_context;
|
||||||
pub use use_root_context::*;
|
pub use use_root_context::*;
|
||||||
|
|
||||||
|
|||||||
@@ -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,10 +1,6 @@
|
|||||||
use dioxus_core::prelude::use_drop;
|
use dioxus_core::prelude::use_drop;
|
||||||
|
|
||||||
#[deprecated(
|
#[deprecated(note = "Use `use_drop` instead, which has the same functionality.")]
|
||||||
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`."
|
|
||||||
)]
|
|
||||||
pub fn use_on_unmount<D: FnOnce() + 'static>(destroy: D) {
|
pub fn use_on_unmount<D: FnOnce() + 'static>(destroy: D) {
|
||||||
use_drop(destroy);
|
use_drop(destroy);
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user