-
Hi, the hackernews and other api examples use https://docs.rs/leptos_reactive/0.1.0/leptos_reactive/fn.create_resource.html for fetching data. However, this strictly requires some input variable. In my case, I just have an api which takes no values. It simply needs to be called. How would I do this? Just giving an empty function as the source makes it never run, and Suspense always goes to the error case. So I assume I am clearly missing something here. I even tried cursed things like this:
But to my surprise, the api is never being called in this case. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
This is surprising: something like a simple Without access to your API, I'm not sure what's going on. I ran a simple test like this, where I just return #[component]
pub fn HomePage(cx: Scope) -> impl IntoView {
let graph = create_resource(cx, || (), move |_| async move { Some(true) });
view! { cx,
<main class="my-0 mx-auto max-w-3xl text-center">
<h1 class="p-6 text-4xl">"Welcome to the Knowledge!"</h1>
<Suspense fallback=|| view! { cx, "Loading..." }>
{move || graph.read().map(|graph| match graph {
None => view! { cx, <div class="item-view">"Error loading the Graph."</div> },
Some(graph) => view! { cx,
<div>
<p>{"Graph loaded"}</p>
</div>
}})
}
</Suspense>
</main>
}
} |
Beta Was this translation helpful? Give feedback.
-
I was wondering exactly the same and came later to the same solution ( Something like this, except the #[component]
pub fn Test(cx: Scope) -> impl IntoView {
let result = create_local_resource(cx, move || (), |_| post_test_alert());
let on_send = move |_| {
result.refetch();
};
view! { cx,
<div class="page">
<button on:click=on_send>"Send"</button>
</div>
}
} |
Beta Was this translation helpful? Give feedback.
This is surprising: something like a simple
|| ()
should work as the trigger if it never needs to change.Without access to your API, I'm not sure what's going on. I ran a simple test like this, where I just return
Some(true)
from the resource, and it seems to work fine.