web_component::prelude::document

Function Style

Source
pub fn Style(props: StyleProps) -> Result<VNode, RenderError>
Expand description

Render a style tag into the head of the page.

If present, the children of the style component must be a single static or formatted string. If there are more children or the children contain components, conditionals, loops, or fragments, the style will not be added.

ยงExample

fn RedBackground() -> Element {
    rsx! {
        // You can use the style component to render a style tag into the head of the page
        // This style tag will set the background color of the page to red
        document::Style {
            r#"
                body {{
                    background-color: red;
                }}
            "#
        }
    }
}

Any updates to the props after the first render will not be reflected in the head.