A direct pending() method (like Action) on LocalResource for use outside Suspense/Transition
#4692
-
ContextFirst, thank you for this fantastic framework — I've been happily building with Leptos and really appreciate the work that has gone into it.
Current workaround and its limitationsThe only way to detect loading state today is to check whether let is_loading = move || resource.get().is_none();This works for the initial load, but breaks for re-fetches: once a resource has resolved once, What would be helpful
let action = Action::new(|input: &String| async { /* ... */ });
let is_pending: Memo<bool> = action.pending();A similar API on let resource = LocalResource::new(|| async { fetch_data().await });
let is_loading: Memo<bool> = resource.pending(); // true during initial load and re-fetches
view! {
<button disabled=move || is_loading.get()>"Submit"</button>
}Is there an existing way to get this signal that I'm missing? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Personally I'd probably use the There isn't a |
Beta Was this translation helpful? Give feedback.
Personally I'd probably use the
set_pendingprop onTransition, which takes a callback that will run whenever it's loading. This allows you to provide a visual cue that it's loading the new data, since it doesn't fall back to the fallback.There isn't a
loadingsignal or similar onLocalResourceor onResource. The primary resource is that when we had them, they made it very easy to shoot yourself in the foot by causing hydration errors when they were used outside Suspense/Transition.