Skip to content

Commit

Permalink
Allow passing class component (#104)
Browse files Browse the repository at this point in the history
* Allow passing class component
  • Loading branch information
roderickhsiao authored Mar 30, 2022
1 parent 063f58d commit 8646cff
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-in-viewport",
"version": "1.0.0-alpha.23",
"version": "1.0.0-alpha.24",
"description": "Track React component in viewport using Intersection Observer API",
"author": "Roderick Hsiao <roderickhsiao@gmail.com>",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion src/lib/handleViewport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const isReactComponent = (Component) => {
};

function handleViewport(
TargetComponent: React.ElementType,
TargetComponent: React.ElementType | React.ComponentClass,
options: Options = defaultOptions,
config: Config = defaultConfig,
) {
Expand Down
37 changes: 18 additions & 19 deletions src/stories/common/themeComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,25 @@ export const PageTitle = memo(
);
PageTitle.displayName = 'PageTitle';

export const Card = memo(
({
titleText,
contentNode,
forwardedRef,
}: {
titleText: string;
contentNode: React.ReactNode;
forwardedRef?: React.Ref<any> | undefined;
}) => (
<div className="card" ref={forwardedRef}>
<div className="card__head">
<h3 className="card__title">{titleText}</h3>
</div>
<div className="card__conent">{contentNode}</div>
</div>
),
);
export class Card extends React.PureComponent<{
titleText: string;
contentNode: React.ReactNode;
forwardedRef?: React.Ref<any> | undefined;
}> {
static displayName = 'Card';

Card.displayName = 'Card';
render() {
const { titleText, contentNode, forwardedRef } = this.props;
return (
<div className="card" ref={forwardedRef}>
<div className="card__head">
<h3 className="card__title">{titleText}</h3>
</div>
<div className="card__conent">{contentNode}</div>
</div>
);
}
}

export function Block(props) {
const {
Expand Down

0 comments on commit 8646cff

Please sign in to comment.