UNPKG

synapse-react-client

Version:

[![npm version](https://badge.fury.io/js/synapse-react-client.svg)](https://badge.fury.io/js/synapse-react-client) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettie

34 lines (33 loc) 970 B
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