Skip to main content

Controls

The controls do the same as their hooks, but can be called from anywhere - API helpers, event handlers, stores and other code outside of React components.

note

The controls work only after <BetterHtmlProvider> has been rendered.

loaderControls​

The same as the useLoaderControls hook.

import { loaderControls } from "react-better-html";

loaderControls.startLoading("savingUser");
loaderControls.stopLoading("savingUser");
loaderControls.toggleLoading("savingUser");

alertControls​

The same as the useAlertControls hook. Requires the alertsPlugin.

import { alertControls } from "react-better-html";

const alert = alertControls.createAlert({ type: "success", message: "User saved" });
alertControls.removeAlert(alert.id);

colorThemeControls​

Changes the color theme. Without an argument it toggles between light and dark.

import { colorThemeControls } from "react-better-html";

colorThemeControls.toggleTheme();
colorThemeControls.toggleTheme("dark");
tip

For a ready UI use the <ColorThemeSwitch> component.

sideMenuControls​

Controls the <SideMenu> component.

import { sideMenuControls } from "react-better-html";

sideMenuControls.collapse(); // expand(), toggleExpanded()
sideMenuControls.open(); // close(), toggleOpened() - mobile only