mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-11 15:07:08 +00:00
Merge branch 'DioxusLabs:master' into master
This commit is contained in:
commit
3b54048fa2
1 changed files with 30 additions and 0 deletions
30
examples/custom_element.rs
Normal file
30
examples/custom_element.rs
Normal file
|
@ -0,0 +1,30 @@
|
|||
//! This example shows to wrap a webcomponent / custom element with a component.
|
||||
//!
|
||||
//! Oftentimes, a third party library will provide a webcomponent that you want
|
||||
//! to use in your application. This example shows how to create that custom element
|
||||
//! directly with the raw_element method on NodeFactory.
|
||||
|
||||
use dioxus::prelude::*;
|
||||
|
||||
fn main() {
|
||||
let mut dom = VirtualDom::new(app);
|
||||
let _ = dom.rebuild();
|
||||
|
||||
let output = dioxus::ssr::render_vdom(&dom);
|
||||
|
||||
println!("{}", output);
|
||||
}
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
let nf = NodeFactory::new(&cx);
|
||||
|
||||
let mut attrs = dioxus::core::exports::bumpalo::collections::Vec::new_in(nf.bump());
|
||||
|
||||
attrs.push(nf.attr("client-id", format_args!("abc123"), None, false));
|
||||
|
||||
attrs.push(nf.attr("name", format_args!("bob"), None, false));
|
||||
|
||||
attrs.push(nf.attr("age", format_args!("47"), None, false));
|
||||
|
||||
Some(nf.raw_element("my-element", None, &[], attrs.into_bump_slice(), &[], None))
|
||||
}
|
Loading…
Reference in a new issue