Skip to content

Commit 9c1e403

Browse files
calebdejiooade
authored andcommitted
refactor: change Container props to as. Return react element.
1 parent 33087f7 commit 9c1e403

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/index.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ interface Props extends React.HTMLAttributes<HTMLElement> {
77
onClickAway: (event: MouseEvent | TouchEvent) => void;
88
mouseEvent?: MouseEvents;
99
touchEvent?: TouchEvents;
10-
Container?: React.ElementType;
10+
as?: React.ElementType;
1111
}
1212

1313
const ClickAwayListener: FunctionComponent<Props> = ({
1414
onClickAway,
1515
mouseEvent = 'click',
1616
touchEvent = 'touchend',
1717
children,
18-
Container = 'div',
18+
as = 'div',
1919
...props
2020
}) => {
2121
let node = useRef<HTMLElement>(null);
@@ -38,11 +38,7 @@ const ClickAwayListener: FunctionComponent<Props> = ({
3838
};
3939
}, [mouseEvent, onClickAway, touchEvent]);
4040

41-
return (
42-
<Container ref={node} {...props}>
43-
{children}
44-
</Container>
45-
);
41+
return React.createElement(as, { ref: node, ...props }, children);
4642
};
4743

4844
export default ClickAwayListener;

0 commit comments

Comments
 (0)