Skip to content

Commit 2c81982

Browse files
committed
feat(utils): more verbose useAppSize usage error message
1 parent dac5e08 commit 2c81982

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

packages/documentation/src/components/DemoSandbox/CodePreview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import cn from "classnames";
33
import { IFiles } from "codesandbox-import-utils/lib/api/define";
44

55
import { CodeBlock } from "components/Code";
6+
import { useTheme } from "components/Theme";
67
import { RMD_VERSION } from "constants/github";
78

89
import FileNotFound from "./FileNotFound";
910

1011
import styles from "./CodePreview.module.scss";
11-
import { useTheme } from "components/Theme";
1212

1313
export interface CodePreviewProps {
1414
fileName: string;

packages/utils/src/sizing/__tests__/useAppSize.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ describe("useAppSize", () => {
4343
consoleError.mockImplementation();
4444

4545
expect(() => render(<Test />)).toThrowError(
46-
"Attempted to use the current `AppSizeContext` without mounting the `AppSizeListener` component beforehand."
46+
"Unable to get the current `AppSize` from `react-md` because the `AppSizeListener` " +
47+
"could not be found when using the `useAppSize` hook. To fix this error, either " +
48+
"initialize the `AppSizeListener` component from `@react-md/utils` or the " +
49+
"`Configuration` component from `@react-md/layout` near the root of your app."
4750
);
4851
});
4952
});

packages/utils/src/sizing/useAppSize.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ export default function useAppSize(): AppSize {
2020
const { __initialized, ...context } = useContext(AppSizeContext);
2121
if (!__initialized) {
2222
throw new Error(
23-
"Attempted to use the current `AppSizeContext` without mounting the `AppSizeListener` component beforehand."
23+
"Unable to get the current `AppSize` from `react-md` because the `AppSizeListener` " +
24+
"could not be found when using the `useAppSize` hook. To fix this error, either " +
25+
"initialize the `AppSizeListener` component from `@react-md/utils` or the " +
26+
"`Configuration` component from `@react-md/layout` near the root of your app."
2427
);
2528
}
2629

0 commit comments

Comments
 (0)