Created
November 27, 2020 13:00
-
-
Save plusgut/6870f5b4506294608d782dbed7fee4d3 to your computer and use it in GitHub Desktop.
This file contains 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
import plusnew, { component, Props, store } from "@plusnew/core"; | |
import { ElementLifecycle } from "@plusnew/driver-dom"; | |
type props = { | |
children: any; | |
}; | |
export default component( | |
__dirname, | |
(Props: Props<props>, componentInstance) => { | |
const show = store(false); | |
const observer = new IntersectionObserver((entries) => { | |
if (entries.some((entry) => entry.isIntersecting)) { | |
show.dispatch(true); | |
} | |
}); | |
componentInstance.registerLifecycleHook("componentWillUnmount", () => | |
observer.disconnect() | |
); | |
return ( | |
<ElementLifecycle | |
elementDidMount={(element) => { | |
observer.observe(element); | |
}} | |
> | |
<div> | |
<show.Observer> | |
{(showState) => | |
showState && <Props>{(props) => props.children}</Props> | |
} | |
</show.Observer> | |
</div> | |
</ElementLifecycle> | |
); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment