Git Product home page Git Product logo

Comments (2)

jkelleyrtp avatar jkelleyrtp commented on June 3, 2024

Problem

Steps To Reproduce

Steps to reproduce the behavior:

fn main() {
launch(client_mod::client_lib::Client);
}

pub fn Client() -> Element {
    println!("Client");

  spawn(async move {
  // do some async things here
  }
}
  • I found that if something changed, the Client(main App component) will be rendered again, so the Client will be printed many times. So that the spawn will generate many times.

Expected behavior Is there a way could spawn new thread in fn main or other places, so I could just spawn a new thread once just like launch().

Screenshots

If applicable, add screenshots to help explain your problem.

Environment:

  • Dioxus version: 0.5.1
  • Rust version: 1.7.75
  • OS info: MacOS
  • App platform: desktop

We have use_future, use_effect, and use_hook depending on how much abstraction you need.

https://docs.rs/dioxus-hooks/latest/dioxus_hooks/fn.use_future.html
https://docs.rs/dioxus-hooks/latest/dioxus_hooks/fn.use_effect.html
https://docs.rs/dioxus-core/0.5.1/dioxus_core/fn.use_hook.html

from dioxus.

jiker-burce avatar jiker-burce commented on June 3, 2024

@jkelleyrtp thanks for the reply. but I found that to use the spawn() in the top element fn() could solve the problem. We should move the values that would be rerendered in the child component.

from dioxus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.