use_previous_and_current

Function use_previous_and_current 

Source
pub fn use_previous_and_current<T: 'static + Clone + PartialEq>(
    value: impl IntoReadable<T>,
) -> State<(T, T)>
Expand description

Track the previous and current values of a reactive value.

This hook returns a State<(T, T)> where the first element is the previous value and the second is the current value. Useful for animations or effects that need to transition between values.

ยงExample

fn app() -> impl IntoElement {
    let value = use_state(|| 0);
    let values: State<(i32, i32)> = use_previous_and_current(value);

    rect().child(format!(
        "Previous: {}, Current: {}",
        values.read().0,
        values.read().1
    ))
}