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,7 +15,7 @@ import React, {
useMemo,
useRef,
} from 'react';
import {useDynamicCallback} from './reactUtils';
import {useDynamicCallback, ReactContextError} from './reactUtils';
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
/**
@ -76,9 +76,7 @@ export function ScrollControllerProvider({
export function useScrollController(): ScrollController {
const context = useContext(ScrollMonitorContext);
if (context == null) {
throw new Error(
'"useScrollController" is used but no context provider was found in the React tree.',
);
throw new ReactContextError('ScrollControllerProvider');
}
return context;
}