contextapi.rs 1.0 KB

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