Skip to content

Why Does use_future Trigger a gRPC Request Right After Screen Render in Dioxus? #3366

Closed Answered by ealmloff
0ung asked this question in Q&A
Discussion options

You must be logged in to vote

use_future always runs when the component is first created. If you want to run a future only when an event is triggered, you can return a future from the event or call spawn in the event like this:

use crate::BASE_URL;
use dioxus::prelude::*;
use proto::{
    authentication_service_client::AuthenticationServiceClient, LoginRequest, LoginResponse,
};
use tonic_web_wasm_client::Client;
use web_sys::{console, wasm_bindgen::JsValue};

pub mod proto {
    tonic::include_proto!("user");
}

pub fn Login() -> Element {
    let mut login_id = use_signal(|| String::new());
    let mut login_password = use_signal(|| String::new());

    let mut handleLogin = move || async move {
        console::log_1(

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by 0ung
Comment options

You must be logged in to vote
0 replies
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