AppRoot is the composition root for a Xanui-powered application. It wraps ThemeProvider (with isRoot forced on), and also mounts DocumentProvider, CSSCacheProvider, AppRootProvider, and BreakpointProvider around your tree — so a single component gives you theme CSS variables, a CSS reset, scrollbar styling, breakpoint context, document context, and a CSS cache scope.
tsx
<AppRoot theme={theme} defaultBreakpoint="lg" noScrollbarCss={false} selectionColor="brand"> {children}</AppRoot>AppRoot is a forwardRef component generic over the rendered tag (defaults to "div"), so ref resolves to the underlying DOM node.
AppRoot extends ThemeProviderProps<T> (which itself extends TagProps<T>), so every prop accepted by ThemeProvider/Tag works here (theme, onThemeUpdate, scrollbar, component, spacing/color/layout props, DOM attributes, etc.). Additional props defined by AppRoot itself:
ThemeProvider with isRoot always set, which injects the CSS reset (box sizing, margin/padding zero, list-style reset, anchor defaults, table/border resets, etc.) and the themed scrollbar CSS (unless noScrollbarCss).BreakpointProvider (defaultKey={defaultBreakpoint ?? "xl"}), so useBreakpoint/useBreakpointProps work immediately.CSSCacheProvider (using CSSCacheId) and DocumentProvider (using document), so useCSSCache/useCSSCacheId/getCSSCache and useDocument resolve correctly, including inside a nested <Iframe>.xuitm) on mount (if not already set) and again whenever onThemeUpdate fires, so the next server render can start with the correct theme and avoid a flash.<style data-oncss> elements found under <body> into <head>.<RenderRenderar /> (unless disableRenderar) so Renderar.render(...) has somewhere to output — see below.tsx
import { AppRoot, createTheme } from 'xanui-core' const theme = createTheme({ name: 'light', mode: 'light' }) export const Root = ({ children }) => ( <AppRoot component="body" theme={theme}> {children} </AppRoot>)tsx
<AppRoot theme={theme} noScrollbarCss> <Dashboard /></AppRoot>scrollbar is forwarded to ThemeProvider:
tsx
<AppRoot theme={theme} scrollbar={{ size: , thumbColor: 'var(--color-neutral-600)', trackColor: 'var(--color-neutral-200)' }}> {children}</AppRoot>tsx
<AppRoot theme={theme} defaultBreakpoint="lg"> {children}</AppRoot>Use AppRoot at the very top of your React tree (e.g., around the contents of document.body). For nested theme islands or styling overrides without the rest of the root behavior, use ThemeProvider directly.
useAppRootElement()Exported alongside AppRoot. Returns the DOM node of the nearest AppRoot (or null during SSR):
tsx
import { useAppRootElement } from 'xanui-core' const rootEl = useAppRootElement()Useful when a portal or overlay needs to stay attached within the themed AppRoot subtree instead of document.body.
RenderarAn imperative, render-anywhere registry that AppRoot wires up automatically via <RenderRenderar /> (rendered as the last child of BreakpointProvider, unless disableRenderar is set). It lets you mount components from outside the React tree — e.g. from an event handler or a utility function — without prop-drilling a portal target:
tsx
import { Renderar } from 'xanui-core' const handle = Renderar.render(MyToast, { message: 'Saved!' }) handle.updateProps({ message: 'Updated!' })handle.unrender()Renderar.render(component, props?) returns { unrender(), updateProps(newProps) }. Each call to Renderar.render adds an entry to an internal list that RenderRenderar re-renders whenever it changes; Renderar.unrender(component) and Renderar.updateProps(component, props) are also available as static methods if you kept a reference to the original component instead of the returned handle.