I am working on a page that has a visibility sensor so that whenever I scroll to that section, the animation starts. However, I only need it to be visible only once.
const [scrollStatus, setScroll] = useState(false);
const contextData = {
stateSetters: {
scrollStatus
}
}
<ScrollContext.Provider value={contextData}>
<VisibilitySensor onChange={() => {
setScroll(!scrollStatus);
}}>
<CountUp start={0} end={scrollStatus ? 0 : 40} duration={1.75} suffix="+"/>
</VisibilitySensor>
</ScrollContext.Provider>
I am currently using hooks and functional components. I have been looking for ways to be able to set the visibility to true once it has been viewed.
The output should become already visible and not visible only every scroll.