synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
34 lines (33 loc) • 970 B
JavaScript
import { jsx as t } from "react/jsx-runtime";
import { Component as n } from "react";
import { InView as r } from "react-intersection-observer";
class l extends n {
constructor(e) {
super(e), this.state = {
hasBeenInView: !1
};
}
render() {
const { rootMargin: e, tag: i } = this.props;
return /* @__PURE__ */ t(
r,
{
as: i || "div",
rootMargin: e,
onChange: this.onVisibilityChange,
children: this.getObserverChildren
}
);
}
getObserverChildren = (e) => {
const { renderInView: i, renderOutOfView: s } = this.props;
return (e.inView || this.state.hasBeenInView) && i ? i() : !e.inView && s ? s() : null;
};
onVisibilityChange = (e) => {
e ? (this.setState({ hasBeenInView: !0 }), this.props.onEnterView && this.props.onEnterView()) : this.props.onLeaveView && this.props.onLeaveView();
};
}
export {
l as default
};
//# sourceMappingURL=VisibilityObserver.js.map