dioxus_lib::prelude::global_attributes

Constant dangerous_inner_html

source
pub const dangerous_inner_html: (&'static str, Option<&'static str>, bool);
Expand description

dangerous_inner_html is Dioxus’s replacement for using innerHTML in the browser DOM. In general, setting HTML from code is risky because it’s easy to inadvertently expose your users to a cross-site scripting (XSS) attack. So, you can set HTML directly from Dioxus, but you have to type out dangerous_inner_html to remind yourself that it’s dangerous

§Usage in rsx

let dangerous_inner_html = "value";

rsx! {
    // Attributes need to be under the element they modify
    div {
        // Attributes are followed by a colon and then the value of the attribute
        dangerous_inner_html: "value"
    }
    div {
        // Or you can use the shorthand syntax if you have a variable in scope that has the same name as the attribute
        dangerous_inner_html,
    }
};