diff --git a/packages/docusaurus-theme-classic/src/theme/ThemeContext.js b/packages/docusaurus-theme-classic/src/theme/ThemeContext.js index b521d46bfc3d..e78020cad7fb 100644 --- a/packages/docusaurus-theme-classic/src/theme/ThemeContext.js +++ b/packages/docusaurus-theme-classic/src/theme/ThemeContext.js @@ -7,10 +7,6 @@ import React from 'react'; -const ThemeContext = React.createContext({ - isDarkTheme: false, - setLightTheme: () => {}, - setDarkTheme: () => {}, -}); +const ThemeContext = React.createContext(); export default ThemeContext; diff --git a/packages/docusaurus-theme-classic/src/theme/UserPreferencesContext.js b/packages/docusaurus-theme-classic/src/theme/UserPreferencesContext.js index eef414681791..81f3675386b9 100644 --- a/packages/docusaurus-theme-classic/src/theme/UserPreferencesContext.js +++ b/packages/docusaurus-theme-classic/src/theme/UserPreferencesContext.js @@ -7,14 +7,6 @@ import {createContext} from 'react'; -const UserPreferencesContext = createContext({ - // Tab group choice. - tabGroupChoices: {}, - setTabGroupChoices: () => {}, - - // Announcement bar. - isAnnouncementBarClosed: false, - closeAnnouncementBar: () => {}, -}); +const UserPreferencesContext = createContext(); export default UserPreferencesContext; diff --git a/packages/docusaurus-theme-classic/src/theme/hooks/useThemeContext.js b/packages/docusaurus-theme-classic/src/theme/hooks/useThemeContext.js index a71392756fa0..b995277a801b 100644 --- a/packages/docusaurus-theme-classic/src/theme/hooks/useThemeContext.js +++ b/packages/docusaurus-theme-classic/src/theme/hooks/useThemeContext.js @@ -10,7 +10,13 @@ import {useContext} from 'react'; import ThemeContext from '@theme/ThemeContext'; function useThemeContext() { - return useContext(ThemeContext); + const context = useContext(ThemeContext); + if (context == null) { + throw new Error( + '`useThemeContext` is used outside of `Layout` Component. See https://v2.docusaurus.io/docs/theme-classic#usethemecontext.', + ); + } + return context; } export default useThemeContext; diff --git a/packages/docusaurus-theme-classic/src/theme/hooks/useUserPreferencesContext.js b/packages/docusaurus-theme-classic/src/theme/hooks/useUserPreferencesContext.js index d35259677322..347829bba9fd 100644 --- a/packages/docusaurus-theme-classic/src/theme/hooks/useUserPreferencesContext.js +++ b/packages/docusaurus-theme-classic/src/theme/hooks/useUserPreferencesContext.js @@ -10,7 +10,13 @@ import {useContext} from 'react'; import UserPreferencesContext from '@theme/UserPreferencesContext'; function useUserPreferencesContext() { - return useContext(UserPreferencesContext); + const context = useContext(UserPreferencesContext); + if (context == null) { + throw new Error( + '`useUserPreferencesContext` is used outside of `Layout` Component.', + ); + } + return context; } export default useUserPreferencesContext;