Skip to main content

ThemeProvider

Function ThemeProvider 

Source
pub fn ThemeProvider(_: ThemeProviderProps) -> Element
Expand description

Theme provider component

Wraps children with theme context. Must be placed near the root of your app. Optionally persists theme selection to localStorage on web.

§Properties

  • children - Child elements to render
  • initial_theme - Optional initial theme (defaults to light theme, or loaded from localStorage if persistence enabled)
  • persist_theme - Whether to save/load theme from localStorage (default: false)

§Example

use dioxus_ui_system::theme::{ThemeProvider, ThemeTokens};

fn App() -> Element {
    rsx! {
        // With persistence
        ThemeProvider { persist_theme: true,
            Home {}
        }
        
        // Without persistence (default)
        ThemeProvider {
            Home {}
        }
    }
}

§Props

For details, see the props struct definition.