Skip to content

use_async with a parameter from state #26

Description

@ctron

Assuming a use-case of:

  • Enter a parameter value
  • Issue the request (with that parameter)

It looks like with the current use_async variant, the future already gets created with every re-render, but not being used until the .run method is somehow invoked.

I think it would be nice to have some kind of "dependency" to the hook, which allows to provide one or more dependencies, parameters, which are being used to generate the future.

Something in the direction of:

#[function_component]
fn component() -> Html {
  let state = use_state_eq(String::new);

  let call = use_async(|input|{
    async move {
      fetch(input); // input = value of state
    }
  }, state.clone());

  let onclick = {
    let call = call.clone();
    use_callack(move |()|{
      call.run();
    })
  };

  html!() // somehow updates `state` (e.g. through an input field)
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions