#use_effect_with => use_future_with

1 messages · Page 1 of 1 (latest)

gloomy patrol
#

Hello 👋 ,

I have a component which looks like the following:

#[function_component(Entries)]
pub fn entries(props: &EntriesProps) -> HtmlResult {
    let results = use_state(|| None);

    let input = props.input.clone();
    {
        let input_clone = input.clone();
        let results = results.clone();

        use_effect_with(input, move |_| {
            let input_clone_clone = input_clone.clone();
            wasm_bindgen_futures::spawn_local(async move {
                let res = search(input_clone_clone.as_deref()).await;
                results.set(Some(res));
            });
            || {}
        });
    }
    
    let html = // ...
    Ok(html)
}

However, I would like to benefit from Suspense and use use_future_with but can't seem to figure out how since it doesn't seem to hook into the component lifecycle.

unique dirge
#

well i dont see the problem, just replace effect/state and get rid of spawn local

#

and have a suspense anywhere as a parent/parents parent of this component

#

so probably like

let results = use_future_with(input, async move ...)?; // ? for HtmlResult
gloomy patrol
#

thanks, it works
something must have changed since I was using use_future originally and it didn't work 🤔