Skip to content

Instantly share code, notes, and snippets.

@theKashey
Created May 9, 2019 23:44
Show Gist options
  • Save theKashey/8b54d9a5c050d8faa929aad9682aa485 to your computer and use it in GitHub Desktop.
Save theKashey/8b54d9a5c050d8faa929aad9682aa485 to your computer and use it in GitHub Desktop.
componentDidMount() {
new IntersectionObserver(async ([entry], obs) => {
if (!entry.isIntersecting) return;
obs.unobserve(this.root);
this.setState({loading: true});
const {load} = this.props;
const Child = interopDefault(await load());
setTimeout(() => {
//ReactDOM.hydrate(<Child {...props} />, this.root);
this.setState({Child, loading: false});
}, 10000);
}).observe(this.root);
}
render() {
const {Child} = this.state;
if (Child) {
return (
<section
ref={c => this.root = c}
>
<Child {...this.props} />
</section>
)
}
return (
<section
ref={c => this.root = c}
dangerouslySetInnerHTML={{__html: ''}}
_suppressHydrationWarning
/>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment