feat: bubbling
This commit is contained in:
1 parent
9bd56ee499
commit
19df1bda10
12 files changed
+398
-292
No files matched your search
@@ -0,0 +1,29 @@
|
||||
//! Example: README.md showcase
|
||||
//!
|
||||
//! The example from the README.md.
|
||||
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_core as dioxus;
|
||||
use dioxus_core_macro::*;
|
||||
use dioxus_hooks::use_state;
|
||||
use dioxus_html as dioxus_elements;
|
||||
use dioxus_web;
|
||||
use gloo_timers::future::TimeoutFuture;
|
||||
|
||||
fn main() {
|
||||
dioxus_web::launch(App, |c| c);
|
||||
}
|
||||
|
||||
static App: FC<()> = |cx, props| {
|
||||
let mut count = use_state(cx, || 0);
|
||||
|
||||
cx.push_task(|| async move {
|
||||
TimeoutFuture::new(100).await;
|
||||
count += 1;
|
||||
});
|
||||
|
||||
rsx!(cx, div {
|
||||
h3 { "High-Five counter: {count}" }
|
||||
button { onclick: move |_| count.set(0), "Reset!" }
|
||||
})
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
#![allow(non_upper_case_globals)]
|
||||
|
||||
//! Example: README.md showcase
|
||||
//!
|
||||
//! The example from the README.md.
|
||||
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_core as dioxus;
|
||||
use dioxus_core_macro::*;
|
||||
use dioxus_html as dioxus_elements;
|
||||
use dioxus_web;
|
||||
|
||||
fn main() {
|
||||
dioxus_web::launch(App, |c| c);
|
||||
}
|
||||
|
||||
static App: FC<()> = |cx, _| {
|
||||
let doggo = cx.suspend(|| async move {
|
||||
#[derive(serde::Deserialize)]
|
||||
struct Doggo {
|
||||
message: String,
|
||||
}
|
||||
|
||||
let src = reqwest::get("https://dog.ceo/api/breeds/image/random")
|
||||
.await
|
||||
.expect("Failed to fetch doggo")
|
||||
.json::<Doggo>()
|
||||
.await
|
||||
.expect("Failed to parse doggo")
|
||||
.message;
|
||||
|
||||
rsx!(cx, img { src: "{src}" })
|
||||
});
|
||||
|
||||
rsx!(cx, div {
|
||||
h1 {"One doggo coming right up"}
|
||||
button { onclick: move |_| cx.needs_update(), "Get a new doggo" }
|
||||
{doggo}
|
||||
})
|
||||
};
|
||||
Reference in new issue
Block a user