deep.rs 1.7 KB

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