contextapi.rs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. println!("Value is {}", props.name);
  18. println!("Value is {}", value.as_str());
  19. println!("Value is {}", *value);
  20. })
  21. .on("click", move |_| {
  22. println!("Value is {}", props.name);
  23. })
  24. .finish()
  25. })
  26. // ctx.view(html! {
  27. // <div>
  28. // <button onclick={move |_| println!("Value is {}", value)} />
  29. // <button onclick={move |_| println!("Value is {}", value)} />
  30. // <button onclick={move |_| println!("Value is {}", value)} />
  31. // <div>
  32. // <p> "Value is: {val}" </p>
  33. // </div>
  34. // </div>
  35. // })
  36. };