fc_macro.rs 988 B

12345678910111213141516171819202122
  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. ///
  15. /// Notice that Context is normally generic over props, but RA doesn't care when in proc-macro mode.
  16. /// Also notice that ctx.props still works like you would expect, so migrating to the macro is easy.
  17. #[fc]
  18. fn example(ctx: &Context, name: String) -> VNode {
  19. html! { <div> "Hello, {name}!" </div> }
  20. }