1
0

custom_element.rs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //! This example shows to wrap a webcomponent / custom element with a component.
  2. //!
  3. //! Oftentimes, a third party library will provide a webcomponent that you want
  4. //! to use in your application. This example shows how to create that custom element
  5. //! directly with the raw_element method on NodeFactory.
  6. use dioxus::prelude::*;
  7. fn main() {
  8. let mut dom = VirtualDom::new(app);
  9. let _ = dom.rebuild();
  10. let output = dioxus_ssr::render(&dom);
  11. println!("{}", output);
  12. }
  13. fn app(cx: Scope) -> Element {
  14. let g = cx.component(component, (), "component");
  15. let c = cx.make_node(g);
  16. cx.render(rsx! {
  17. div { c }
  18. })
  19. // let nf = NodeFactory::new(cx);
  20. // let mut attrs = dioxus::core::exports::bumpalo::collections::Vec::new_in(nf.bump());
  21. // attrs.push(nf.attr("client-id", format_args!("abc123"), None, false));
  22. // attrs.push(nf.attr("name", format_args!("bob"), None, false));
  23. // attrs.push(nf.attr("age", format_args!("47"), None, false));
  24. // Some(nf.raw_element("my-element", None, &[], attrs.into_bump_slice(), &[], None))
  25. }
  26. fn component(cx: Scope) -> Element {
  27. todo!()
  28. }