mirror of
https://github.com/DioxusLabs/dioxus
synced 2025-02-22 00:28:28 +00:00
chore: Clean up use_on_destroy
docs (#2199)
* chore: Clean up `use_on_destroy` docs * fmt
This commit is contained in:
parent
57e05dcf3a
commit
7949fcda9a
3 changed files with 1 additions and 35 deletions
packages/hooks/src
|
@ -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::*;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
#[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);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue