Skip to main content

use_theme

Function use_theme 

Source
pub fn use_theme() -> ThemeContext
Expand description

Hook to access the theme context

§Panics

Panics if called outside of a ThemeProvider

§Example

use dioxus_ui_system::theme::use_theme;

fn MyComponent() -> Element {
    let theme = use_theme();
    let bg_color = theme.tokens.read().colors.background.to_rgba();
     
    rsx! {
        div { style: "background-color: {bg_color}", "Hello" }
    }
}