1
0

infer.rs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. use dioxus_core as dioxus;
  2. use dioxus_core::{events::on::MouseEvent, prelude::*};
  3. use dioxus_web::WebsysRenderer;
  4. fn main() {
  5. // Setup logging
  6. wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));
  7. console_error_panic_hook::set_once();
  8. log::info!("hello world");
  9. wasm_bindgen_futures::spawn_local(WebsysRenderer::start(Example));
  10. }
  11. // this is a component
  12. static Example: FC<()> = |cx| {
  13. let (event, set_event) = use_state(&cx, || None);
  14. let handler = move |evt| {
  15. set_event(Some(evt));
  16. };
  17. log::info!("hello world");
  18. cx.render(rsx! {
  19. div {
  20. class: "py-12 px-4 w-full max-w-2xl mx-auto bg-red-100"
  21. span {
  22. class: "text-sm font-semibold"
  23. "Dioxus Example: Synthetic Events"
  24. }
  25. button {
  26. class: "inline-block py-4 px-8 mr-6 leading-none text-white bg-indigo-600 hover:bg-indigo-900 font-semibold rounded shadow"
  27. "press me"
  28. }
  29. pre {
  30. onmousemove: {handler}
  31. id: "json"
  32. "Hello world"
  33. }
  34. Example2 { name: "Blah".into() }
  35. }
  36. })
  37. };
  38. #[derive(Debug, PartialEq, Props)]
  39. struct ExampleProps {
  40. name: String,
  41. }
  42. static Example2: FC<ExampleProps> = |cx| {
  43. cx.render(rsx! {
  44. div {
  45. h1 {"hello {cx.name}"}
  46. }
  47. })
  48. };