Skip to content

Commit

Permalink
feat(utils): more verbose useAppSize usage error message
Browse files Browse the repository at this point in the history
  • Loading branch information
mlaursen committed Sep 2, 2020
1 parent dac5e08 commit 2c81982
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import cn from "classnames";
import { IFiles } from "codesandbox-import-utils/lib/api/define";

import { CodeBlock } from "components/Code";
import { useTheme } from "components/Theme";
import { RMD_VERSION } from "constants/github";

import FileNotFound from "./FileNotFound";

import styles from "./CodePreview.module.scss";
import { useTheme } from "components/Theme";

export interface CodePreviewProps {
fileName: string;
Expand Down
5 changes: 4 additions & 1 deletion packages/utils/src/sizing/__tests__/useAppSize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ describe("useAppSize", () => {
consoleError.mockImplementation();

expect(() => render(<Test />)).toThrowError(
"Attempted to use the current `AppSizeContext` without mounting the `AppSizeListener` component beforehand."
"Unable to get the current `AppSize` from `react-md` because the `AppSizeListener` " +
"could not be found when using the `useAppSize` hook. To fix this error, either " +
"initialize the `AppSizeListener` component from `@react-md/utils` or the " +
"`Configuration` component from `@react-md/layout` near the root of your app."
);
});
});
5 changes: 4 additions & 1 deletion packages/utils/src/sizing/useAppSize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export default function useAppSize(): AppSize {
const { __initialized, ...context } = useContext(AppSizeContext);
if (!__initialized) {
throw new Error(
"Attempted to use the current `AppSizeContext` without mounting the `AppSizeListener` component beforehand."
"Unable to get the current `AppSize` from `react-md` because the `AppSizeListener` " +
"could not be found when using the `useAppSize` hook. To fix this error, either " +
"initialize the `AppSizeListener` component from `@react-md/utils` or the " +
"`Configuration` component from `@react-md/layout` near the root of your app."
);
}

Expand Down

0 comments on commit 2c81982

Please sign in to comment.