Macro wasm_react::h
source · [−]macro_rules! h {
($tag:literal $( [$( #$id:literal )? $( .$( $classnames:tt )+ )?] )?) => { ... };
($tag:ident $( [$( #$id:literal )? $( .$( $classnames:tt )+ )?] )?) => { ... };
}
Expand description
A convenience macro to create_element()
for
creating HTML element nodes.
Returns an H<HtmlTag>
struct that provides
auto-completion for HTML attributes and events.
Example
h!(div)
.attr("id", &"app".into())
.build(c![
h!(h1).build(c!["Hello World!"])
])
// <div id="app"><h1>Hello World!</h1></div>
h!("web-component")
.build(c!["Hello World!"])
// <web-component>Hello World!</web-component>
It is also possible to add an id and/or classes to the element using a terse
notation. You can use the same syntax as classnames!
.
h!(div[#"app"."some-class"."warning"])
.build(c!["This is a warning!"])
// <div id="app" class="some-class warning">This is a warning!</div>