euv_ui/hook/use_async/fn.rs
1use super::*;
2
3/// Obtains the `UseAsyncHandle` registered against the current hook
4/// context slot.
5///
6/// Behaves like `HookContext::use_hook`: the same handle (and therefore
7/// the same `state` signal) is returned on every render at the same hook
8/// index, so state written by `set_state` / `refetch` survives re-renders.
9/// Without the hook context (e.g. when called outside a render cycle) the
10/// factory falls back to a stand-alone handle — see
11/// [`UseAsyncHandle::new_for_fallback`].
12///
13/// The returned handle is `Copy`, cheap to pass around, and exposes
14/// `state()` / `set_state()` for non-async testing as well as
15/// `refetch()` for the real wasm path. Render code subscribes to state
16/// changes by reading `state()` inside a render closure.
17///
18/// # Returns
19///
20/// - `UseAsyncHandle<T, L>` - The async handle in the `Loading`
21/// initial state, ready for an `refetch(...)` from the call site.
22pub fn use_async<T, L>() -> UseAsyncHandle<T, L>
23where
24 T: Clone + PartialEq + 'static,
25 L: Clone + PartialEq + HasLoadingHint + 'static,
26{
27 HookContext::use_hook(UseAsyncHandle::new_for_fallback)
28}