infer.rs 1.5 KB

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