2
0
Fork 0
mirror of https://github.com/DioxusLabs/dioxus synced 2025-02-22 08:38:27 +00:00

chore: Clean up use_on_destroy docs ()

* chore: Clean up `use_on_destroy` docs

* fmt
This commit is contained in:
Marc Espin 2024-04-01 16:20:04 +02:00 committed by GitHub
parent 57e05dcf3a
commit 7949fcda9a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 1 additions and 35 deletions

View file

@ -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::*;

View file

@ -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;
});
}
}

View file

@ -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);
}