Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
componentDidMount() {
if (this.state.resolved != null) {
return;
}
const {defer = DeferTiming.Mount} = this.props;
if (this.props.defer === DeferTiming.Idle) {
if ('requestIdleCallback' in window) {
this.idleCallbackHandle = (window as WindowWithRequestIdleCallback).requestIdleCallback(
this.load,
);
} else {
this.load();
}
} else if (defer === DeferTiming.Mount) {
this.load();
}
}
);
useEffect(() => {
if (defer == null || defer === DeferTiming.Mount) {
load();
} else if (typeof defer === 'function' && defer(props)) {
load();
}
}, [defer, load, props]);
if (typeof defer === 'function') {
return null;
}
switch (defer) {
case DeferTiming.Idle:
return ;
case DeferTiming.InViewport:
return (
);
default:
return null;
}
}
React.useEffect(() => {
if (defer === DeferTiming.Idle) {
if ('requestIdleCallback' in window) {
idleCallbackHandle.current = (window as WindowWithRequestIdleCallback).requestIdleCallback(
loadRemote,
);
} else {
loadRemote();
}
} else if (defer === DeferTiming.Mount) {
loadRemote();
}
return () => {
if (
idleCallbackHandle.current != null &&
typeof (window as any).cancelIdleCallback === 'function'
) {