infer.rs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. use dioxus_core::{events::on::MouseEvent, prelude::*};
  2. use dioxus_web::WebsysRenderer;
  3. fn main() {
  4. // Setup logging
  5. wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));
  6. console_error_panic_hook::set_once();
  7. log::info!("hello world");
  8. wasm_bindgen_futures::spawn_local(WebsysRenderer::start(Example));
  9. }
  10. // this is a component
  11. static Example: FC<()> = |ctx, _props| {
  12. let (event, set_event) = use_state(&ctx, || None);
  13. let event = format!("{:#?}", event);
  14. let handler = move |evt: MouseEvent| {
  15. set_event(Some(evt));
  16. };
  17. log::info!("hello world");
  18. ctx.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. "{event}"
  33. }
  34. // Example2 { name: "{event}".to_string() }
  35. }
  36. })
  37. };
  38. #[derive(Debug, PartialEq, Props)]
  39. struct ExampleProps {
  40. name: String
  41. }
  42. static Example2: FC<ExampleProps> = |ctx, props| {
  43. ctx.render(rsx!{
  44. div {
  45. h1 {"hello {props.name}"}
  46. }
  47. })
  48. };
  49. impl Properties for ExampleProps {
  50. type Builder = ExamplePropsBuilder<((),)>;
  51. type StaticOutput = ExampleProps;
  52. fn builder() -> Self::Builder {
  53. ExampleProps::builder()
  54. }
  55. unsafe fn into_static(self) -> Self::StaticOutput {
  56. todo!()
  57. }
  58. }