contextapi.rs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. use std::{borrow::Borrow, marker::PhantomData, ops::Deref};
  2. use builder::{button, div};
  3. use dioxus_core::prelude::*;
  4. fn main() {}
  5. struct SomeContext {
  6. items: Vec<String>,
  7. }
  8. struct Props {
  9. name: String,
  10. }
  11. #[allow(unused)]
  12. static Example: FC<Props> = |ctx, props| {
  13. let value = ctx.use_context(|c: &SomeContext| c.items.last().unwrap());
  14. ctx.view(move |bump| {
  15. button(bump)
  16. .on("click", move |_| {
  17. // //
  18. println!("Value is {}", props.name);
  19. println!("Value is {}", value.as_str());
  20. println!("Value is {}", *value);
  21. })
  22. //
  23. .on("click", move |_| {
  24. println!("Value is {}", props.name);
  25. })
  26. .finish()
  27. })
  28. // ctx.view(html! {
  29. // <div>
  30. // <button onclick={move |_| println!("Value is {}", value)} />
  31. // <button onclick={move |_| println!("Value is {}", value)} />
  32. // <button onclick={move |_| println!("Value is {}", value)} />
  33. // <div>
  34. // <p> "Value is: {val}" </p>
  35. // </div>
  36. // </div>
  37. // })
  38. };