fc_macro.rs 781 B

12345678910111213141516171819
  1. use dioxus::prelude::*;
  2. use dioxus_ssr::TextRenderer;
  3. // todo @Jon, support components in the html! macro
  4. // let renderer = TextRenderer::new(|_| html! {<Example name="world"/>});
  5. fn main() {
  6. let renderer = TextRenderer::<()>::new(|_| html! {<div> "Hello world" </div>});
  7. let output = renderer.render();
  8. }
  9. /// An example component that demonstrates how to use the functional_component macro
  10. /// This macro makes writing functional components elegant, similar to how Rocket parses URIs.
  11. ///
  12. /// You don't actually *need* this macro to be productive, but it makes life easier, and components cleaner.
  13. /// This approach also integrates well with tools like Rust-Analyzer
  14. #[fc]
  15. fn example(ctx: &Context, name: String) -> VNode {
  16. html! { <div> "Hello, {name}!" </div> }
  17. }