2021-06-01 22:33:15 +00:00
|
|
|
use std::rc::Rc;
|
|
|
|
|
2021-06-22 21:20:54 +00:00
|
|
|
use dioxus_core as dioxus;
|
2021-03-14 00:11:06 +00:00
|
|
|
use dioxus_web::{dioxus::prelude::*, WebsysRenderer};
|
2021-03-13 15:02:57 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));
|
|
|
|
console_error_panic_hook::set_once();
|
|
|
|
|
2021-03-14 00:11:06 +00:00
|
|
|
wasm_bindgen_futures::spawn_local(WebsysRenderer::start(CustomA))
|
2021-03-13 15:02:57 +00:00
|
|
|
}
|
|
|
|
|
2021-06-01 22:33:15 +00:00
|
|
|
fn CustomA(ctx: Context<()>) -> VNode {
|
|
|
|
let (val, set_val) = use_state(&ctx, || "abcdef".to_string() as String);
|
2021-03-26 19:50:28 +00:00
|
|
|
|
2021-03-14 00:11:06 +00:00
|
|
|
ctx.render(rsx! {
|
2021-03-13 15:02:57 +00:00
|
|
|
div {
|
2021-03-14 00:11:06 +00:00
|
|
|
class: "m-8"
|
2021-03-13 15:02:57 +00:00
|
|
|
"CustomA {val}"
|
|
|
|
button {
|
|
|
|
"Upper"
|
2021-03-29 16:31:47 +00:00
|
|
|
onclick: move |_| set_val(val.to_ascii_uppercase())
|
2021-03-13 15:02:57 +00:00
|
|
|
}
|
|
|
|
button {
|
|
|
|
"Lower"
|
2021-03-29 16:31:47 +00:00
|
|
|
onclick: move |_| set_val(val.to_ascii_lowercase())
|
2021-03-13 15:02:57 +00:00
|
|
|
}
|
2021-05-15 16:03:08 +00:00
|
|
|
components::CustomB {
|
2021-06-01 22:33:15 +00:00
|
|
|
val: val.clone()
|
2021-03-13 15:02:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-03-14 00:11:06 +00:00
|
|
|
mod components {
|
2021-06-01 22:33:15 +00:00
|
|
|
use std::rc::Rc;
|
|
|
|
|
2021-03-14 00:11:06 +00:00
|
|
|
use super::*;
|
2021-03-13 15:02:57 +00:00
|
|
|
|
2021-03-14 00:11:06 +00:00
|
|
|
#[derive(Debug, Props, PartialEq)]
|
2021-06-01 22:33:15 +00:00
|
|
|
pub struct PropsB {
|
|
|
|
val: String,
|
2021-03-14 00:11:06 +00:00
|
|
|
}
|
|
|
|
|
2021-06-01 22:33:15 +00:00
|
|
|
pub fn CustomB(ctx: Context<PropsB>) -> VNode {
|
|
|
|
let (first, last) = ctx.val.split_at(3);
|
2021-03-14 00:11:06 +00:00
|
|
|
ctx.render(rsx! {
|
|
|
|
div {
|
|
|
|
class: "m-8"
|
2021-06-01 22:33:15 +00:00
|
|
|
"CustomB {ctx.val}"
|
2021-03-14 00:11:06 +00:00
|
|
|
CustomC {
|
2021-06-01 22:33:15 +00:00
|
|
|
val: first.to_string()
|
2021-03-14 00:11:06 +00:00
|
|
|
}
|
|
|
|
CustomC {
|
2021-06-01 22:33:15 +00:00
|
|
|
val: last.to_string()
|
2021-03-14 00:11:06 +00:00
|
|
|
}
|
2021-03-13 15:02:57 +00:00
|
|
|
}
|
2021-03-14 00:11:06 +00:00
|
|
|
})
|
|
|
|
}
|
2021-03-13 15:02:57 +00:00
|
|
|
|
2021-03-14 00:11:06 +00:00
|
|
|
#[derive(Debug, Props, PartialEq)]
|
2021-06-01 22:33:15 +00:00
|
|
|
struct PropsC {
|
|
|
|
val: String,
|
2021-03-14 00:11:06 +00:00
|
|
|
}
|
2021-03-13 15:02:57 +00:00
|
|
|
|
2021-06-01 22:33:15 +00:00
|
|
|
fn CustomC(ctx: Context<PropsC>) -> VNode {
|
2021-03-14 00:11:06 +00:00
|
|
|
ctx.render(rsx! {
|
|
|
|
div {
|
|
|
|
class: "m-8"
|
2021-06-01 22:33:15 +00:00
|
|
|
"CustomC {ctx.val}"
|
2021-03-14 00:11:06 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2021-03-13 15:02:57 +00:00
|
|
|
}
|