Skip to content

Provide global HttpClient to use_future #832

Discussion options

You must be logged in to vote

You can use a Lazy static variable to initialize FetchHttpClient:

static CLIENT: once_cell::sync::Lazy = once_cell::sync::Lazy(|| FetchHttpClient::new("http://127.0.0.1:8000"));

#[allow(non_snake_case)]
pub fn App(cx: Scope) -> Element {
    let slides = use_slides(cx);

    cx.render(match slides.value() {
        Some(slides) => rsx! { Slideshow { slides: slides } },
        None => rsx! { div { "Loading slides..." } },
    })
}
pub fn use_slides(cx: &ScopeState) -> &UseFuture<Slides> {
    use_future(cx, (), |_| async move { get_slides(&CLIENT).await })
}

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@ealmloff
Comment options

@patrick-dedication
Comment options

@patrick-dedication
Comment options

@ealmloff
Comment options

@patrick-dedication
Comment options

Answer selected by patrick-dedication
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #831 on February 19, 2023 13:58.