Files
dioxus/packages/hooks/src/use_memo.rs
T
Jonathan Kelley 4f1d039bad clean up prelude (#4416)
* clear away prelude on dioxus

* clippy

* wip - drop prelude from dioxus-html

* docs clippy

* wip

* more fixe

* delete all preludes

* doc...

* better export

* merge some imports

* fewer global imports

* global incremental renderer

* fix cargo doc
2025-07-16 16:04:13 -07:00

15 lines
540 B
Rust

use crate::use_callback;
use dioxus_core::use_hook;
use dioxus_signals::Memo;
#[doc = include_str!("../docs/derived_state.md")]
#[doc = include_str!("../docs/rules_of_hooks.md")]
#[doc = include_str!("../docs/moving_state_around.md")]
#[track_caller]
pub fn use_memo<R: PartialEq>(mut f: impl FnMut() -> R + 'static) -> Memo<R> {
let callback = use_callback(move |_| f());
let caller = std::panic::Location::caller();
#[allow(clippy::redundant_closure)]
use_hook(|| Memo::new_with_location(move || callback(()), caller))
}