--- title: useTheme description: "`useTheme`は、テーマを取得したりテーマを切り替えるための関数を返すカスタムフックです。" links: - source: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/hooks/use-theme - storybook: https://yamada-ui.github.io/yamada-ui?path=/story/hooks-usetheme--basic --- ```tsx const { theme } = useTheme() return {JSON.stringify(theme)} ``` ## 使い方 ```tsx import { useTheme } from "@yamada-ui/react" ``` ```tsx import { useTheme } from "@/components/ui" ``` ```tsx import { useTheme } from "@workspaces/ui" ``` ```tsx const { themeScheme, changeThemeScheme } = useTheme() ``` :::note テーマについて詳しくは、[こちら](https://yamada-ui.com/docs/theming.md)をご覧ください。 ::: ### テーマを切り替える ```tsx const { themeScheme, changeThemeScheme } = useTheme() return ( The current scheme is "{themeScheme}" Primary Secondary Primary Secondary ) ``` :::warning テーマを切り替えるには、複数のテーマを用意する必要があります。詳しくは、[こちら](https://yamada-ui.com/docs/theming/switching-themes.md)をご覧ください。 :::