Skip to content

Commit

Permalink
chore: fix types on component
Browse files Browse the repository at this point in the history
  • Loading branch information
yocontra committed Sep 16, 2022
1 parent 54e46a8 commit c968860
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions dist/react-responsive.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/react-responsive.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/react-responsive.min.js.map

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions src/Component.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import useMediaQuery from './useMediaQuery';
import { ReactNode, FC, CSSProperties } from 'react';
import { ReactNode, ReactElement, FC, CSSProperties } from 'react';
import { MediaQueryAllQueryable, MediaQueryMatchers } from './types';

interface MediaQueryProps extends MediaQueryAllQueryable {
component?: ReactNode
// eslint-disable-next-line @typescript-eslint/ban-types
children?: ReactNode | Function;
children?: ReactNode | ((matches: boolean) => ReactNode);
query?: string;
style?: CSSProperties;
className?: string;
Expand All @@ -15,6 +15,7 @@ interface MediaQueryProps extends MediaQueryAllQueryable {
onChange?: (_matches: boolean) => void;
}

// ReactNode and ReactElement typings are a little funky for functional components, so the ReactElement cast is needed on the return
const MediaQuery: FC<MediaQueryProps> = ({
children,
device,
Expand All @@ -24,9 +25,9 @@ const MediaQuery: FC<MediaQueryProps> = ({
const matches = useMediaQuery(settings, device, onChange);

if (typeof children === 'function') {
return children(matches);
return children(matches) as ReactElement;
}
return matches ? children : null;
return matches ? children as ReactElement : null;
};

export default MediaQuery;

0 comments on commit c968860

Please sign in to comment.