readme.rs 1003 B

12345678910111213141516171819202122232425262728293031323334353637
  1. //! Example: README.md showcase
  2. //!
  3. //! The example from the README.md
  4. use dioxus::prelude::*;
  5. fn main() {
  6. dioxus::web::launch(Example)
  7. }
  8. fn Example(cx: Context<()>) -> VNode {
  9. let name = use_state(&cx, || "..?");
  10. cx.render(rsx! {
  11. h1 { "Hello, {name}" }
  12. button { "?", onclick: move |_| name.set("world!")}
  13. button { "?", onclick: move |_| name.set("Dioxus 🎉")}
  14. })
  15. }
  16. static Example2: FC<()> = |cx| {
  17. let (g, set_g) = use_state_classic(&cx, || 0);
  18. let v = (0..10).map(|f| {
  19. dioxus::prelude::LazyNodes::new(move |__cx: &NodeFactory| {
  20. __cx.element(dioxus_elements::li)
  21. .listeners([dioxus::events::on::onclick(__cx, move |_| set_g(10))])
  22. .finish()
  23. })
  24. });
  25. cx.render(dioxus::prelude::LazyNodes::new(
  26. move |__cx: &NodeFactory| {
  27. __cx.element(dioxus_elements::div)
  28. .children([__cx.fragment_from_iter(v)])
  29. .finish()
  30. },
  31. ))
  32. };