deep.rs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. use std::rc::Rc;
  2. use dioxus::prelude::*;
  3. use dioxus_core as dioxus;
  4. use dioxus_html as dioxus_elements;
  5. fn main() {
  6. wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));
  7. console_error_panic_hook::set_once();
  8. wasm_bindgen_futures::spawn_local(dioxus_web::WebsysRenderer::start(CustomA))
  9. }
  10. fn CustomA(cx: Context<()>) -> DomTree {
  11. let (val, set_val) = use_state_classic(cx, || "abcdef".to_string() as String);
  12. cx.render(rsx! {
  13. div {
  14. class: "m-8"
  15. "CustomA {val}"
  16. button {
  17. "Upper"
  18. onclick: move |_| set_val(val.to_ascii_uppercase())
  19. }
  20. button {
  21. "Lower"
  22. onclick: move |_| set_val(val.to_ascii_lowercase())
  23. }
  24. components::CustomB {
  25. val: val.clone()
  26. }
  27. }
  28. })
  29. }
  30. mod components {
  31. use std::rc::Rc;
  32. use super::*;
  33. #[derive(Debug, Props, PartialEq)]
  34. pub struct PropsB {
  35. val: String,
  36. }
  37. pub fn CustomB(cx: Context<PropsB>) -> DomTree {
  38. let (first, last) = cx.val.split_at(3);
  39. cx.render(rsx! {
  40. div {
  41. class: "m-8"
  42. "CustomB {cx.val}"
  43. CustomC {
  44. val: first.to_string()
  45. }
  46. CustomC {
  47. val: last.to_string()
  48. }
  49. }
  50. })
  51. }
  52. #[derive(Debug, Props, PartialEq)]
  53. struct PropsC {
  54. val: String,
  55. }
  56. fn CustomC(cx: Context<PropsC>) -> DomTree {
  57. cx.render(rsx! {
  58. div {
  59. class: "m-8"
  60. "CustomC {cx.val}"
  61. }
  62. })
  63. }
  64. }