Closed luojinghui closed 2 years ago
Works for me.
@george-dotdev What type definitions are you using?
@sunknudsen Hmm actually I'm not sure. I think I made a mistake when I commented on here. Sorry
I added this type definition to my project and it works:
declare module "react-lazy-load" { import { Component, ReactNode } from "react";
export interface LazyLoadProps {
className?: string;
height?: number | string;
width?: number | string;
debounce?: boolean;
elementType?: string;
offset?: number;
offsetBottom?: number;
offsetHorizontal?: number;
offsetLeft?: number;
offsetRight?: number;
offsetTop?: number;
offsetVertical?: number;
threshold?: number;
children?: ReactNode;
throttle?: number | boolean;
onContentVisible?: Function;
}
export default class LazyLoad extends Component<LazyLoadProps> {
constructor(props: LazyLoad);
}
}
And sorry code formating in the comment didnt work somehow
Thanks for sharing the type declarations @JohannesMerkt. I made some updates to your logic:
onContentVisible?: Function;
with onContentVisible?: () => void;
declare module "react-lazy-load" {
import { FC, ReactNode } from "react";
interface Props {
className?: string;
height?: number | string;
width?: number | string;
debounce?: boolean;
elementType?: string;
offset?: number;
offsetBottom?: number;
offsetHorizontal?: number;
offsetLeft?: number;
offsetRight?: number;
offsetTop?: number;
offsetVertical?: number;
threshold?: number;
children?: ReactNode;
throttle?: number | boolean;
onContentVisible?: () => void;
}
const LazyLoad: FC<Props> = (props) => {};
export default LazyLoad;
}
@grafluxe aweseome! Thanks for sharing it.
Hah I just noticed this after working on converting this library to TS, fortunately the types were pretty straight forward, exactly what I came up with as well.
https://github.com/loktar00/react-lazy-load/tree/feature/update-to-18
Should be fixed with 4.0 and #155
Typescript react not supported?