--- layout: default title: "ToggleThemeButton" --- # `` The `` component lets users switch from light to dark mode, and persists that choice by leveraging the [store](./Store.md). It is enabled by default in the `` as React-admin provides a [built-in dark theme](./AppTheme.md#default). ## Usage You can add the `` to a custom [``](./AppBar.md#toolbar): ```jsx // in src/MyAppBar.js import { AppBar, ToggleThemeButton } from 'react-admin'; export const MyAppBar = () => ( } /> ); ``` Then, pass the custom App Bar in a custom ``, and the `` to your ``. The `` must define a `darkTheme` prop for the button to work: {% raw %} ```jsx import { Admin, Layout } from 'react-admin'; import { MyAppBar } from './MyAppBar'; const MyLayout = ({ children }) => ( {children} ); const App = () => ( ... ); ``` {% endraw %} ## Removing The Button From The AppBar The `` appears by default in the ``. If you want to remove it, you have two solutions: - you can set the `` `darkTheme` prop to `null`: ```tsx // in src/App.tsx const App = () => ( // ... ); ``` - or you can set a custom [`` prop](./AppBar.md#toolbar): ```tsx // in src/MyAppBar.tsx import { AppBar, LocalesMenuButton, RefreshIconButton } from 'react-admin'; export const MyAppBar = () => ( {/* no ToggleThemeButton here */} } /> ); ``` ## Creating A Dark Theme For this button to work, you must provide a dark theme to the `` component. React-admin provides a [built-in dark theme](./AppTheme.md#default), but you can override it according to your needs. The `darkTheme` should be a JSON object that follows the [Material UI theme specification](https://material-ui.com/customization/theming/). You can create such a theme from scratch: ```jsx const darkTheme = { palette: { mode: 'dark' }, }; ``` Of you can override react-admin's default dark theme: ```jsx import { defaultDarkTheme } from 'react-admin'; const darkTheme = { ...defaultDarkTheme, palette: { ...defaultDarkTheme.palette, primary: { main: '#90caf9', }, }, }; ``` **Tip**: React-admin calls Material UI's `createTheme()` on the `` prop - don't call it yourself.