1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
use super::{use_memo, Deps};
use crate::callback::{Callback, PersistedCallback};
/// Returns a persisted, memoized callback.
pub fn use_callback<T, U, D>(
f: impl FnMut(T) -> U + 'static,
deps: Deps<D>,
) -> PersistedCallback<T, U>
where
T: 'static,
U: 'static,
D: PartialEq + 'static,
{
let memo = use_memo(move || Callback::new(f), deps);
let value = memo.value();
PersistedCallback(value.clone())
}