2021-03-25 12:55:15 +03:00
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
export default class extends React.Component {
|
|
|
|
componentDidMount() {
|
|
|
|
this.observer = new IntersectionObserver((entries) => {
|
|
|
|
if (entries[0].isIntersecting) {
|
|
|
|
this.props.onVisible && this.props.onVisible()
|
|
|
|
this.observer.unobserve(this.element);
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
threshold: 0
|
|
|
|
});
|
|
|
|
|
|
|
|
this.observer.observe(this.element);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
2022-02-08 22:57:39 +03:00
|
|
|
this.observer && this.observer.unobserve(this.element);
|
2021-03-25 12:55:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2021-06-15 10:34:43 +03:00
|
|
|
<div
|
|
|
|
ref={(el) => { this.element = el }}
|
|
|
|
className={this.props.className}
|
|
|
|
style={this.props.style}
|
|
|
|
>
|
|
|
|
{this.props.children}
|
|
|
|
</div>
|
2021-03-25 12:55:15 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|