# useColorMode
> Reads the colour mode of the page, and sets and stores it.

Returns the [colour mode](https://next.wave-design-system.pages.dev/get-started/color-modes.md) of the page and a function that sets the mode and stores it. The mode follows a change from any source, including another window of the app.

## Import

```js
import { useColorMode } from '@volue/wave-react';
```

## Example

The example switches the mode of this site.

```jsx
() => {
  const [colorMode, setColorMode] = useColorMode();

  return (
    <FormField.Root as={Flex} flow="column">
      <FormField.Label as="div">{'Colour mode'}</FormField.Label>
      <SingleSelectMenu.Root value={colorMode} onValueChange={setColorMode}>
        <SingleSelectMenu.Trigger />
        <SingleSelectMenu.Content>
          <SingleSelectMenu.Item value="system">
            {'System'}
          </SingleSelectMenu.Item>
          <SingleSelectMenu.Item value="light">{'Light'}</SingleSelectMenu.Item>
          <SingleSelectMenu.Item value="dark">{'Dark'}</SingleSelectMenu.Item>
        </SingleSelectMenu.Content>
      </SingleSelectMenu.Root>
    </FormField.Root>
  );
};
```

> **Important**
>
> `useColorMode` does not apply the stored mode when a page loads. Render `colorModeScript` in the `<head>` for that, as [Let people switch the mode](https://next.wave-design-system.pages.dev/get-started/color-modes.md#let-people-switch-the-mode) shows.

> **Tip**
>
> On the server and during hydration, `useColorMode` returns `undefined`, because the server cannot know the stored mode. Render a neutral state for `undefined`, such as a mode switch with no option selected.

---

## API reference

### Returns

`[colorMode: ColorMode | undefined, setColorMode: (mode: ColorMode | string) => void]`. A tuple similar to `useState`. `ColorMode` is `'light' | 'dark' | 'system'`. `colorMode` is `undefined` on the server and during hydration, and `light` when the root element has no `data-wave-color-mode` attribute. `setColorMode` sets the mode on the root element and stores it in local storage. It takes any string, such as the value of a select, and ignores one that is not a mode.
