deep.rs 1.6 KB

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