Created
May 9, 2019 23:44
-
-
Save theKashey/8b54d9a5c050d8faa929aad9682aa485 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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