refactor(theme-common): unify missing context errors (#6826)

* refactor(theme-common): unify missing context errors

* update test

* more robust
This commit is contained in:
Joshua Chen 2022-03-03 22:26:56 +08:00 committed by GitHub
parent 5c60f41e1b
commit c387a177e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 35 additions and 28 deletions

View file

@ -15,6 +15,7 @@ import React, {
type ReactNode,
} from 'react';
import {createStorageSlot, listStorageKeys} from './storageUtils';
import {ReactContextError} from './reactUtils';
const TAB_CHOICE_PREFIX = 'docusaurus.tab.';
@ -82,9 +83,7 @@ export function TabGroupChoiceProvider({
export function useTabGroupChoice(): TabGroupChoiceContextValue {
const context = useContext(TabGroupChoiceContext);
if (context == null) {
throw new Error(
'"useUserPreferencesContext" is used outside of "Layout" component.',
);
throw new ReactContextError('TabGroupChoiceProvider');
}
return context;
}