Code Monkey home page Code Monkey logo

Comments (7)

JadSayegh avatar JadSayegh commented on September 23, 2024 1

Hey @joshwnj , I'm trying to use it to trigger an animation on a component (animated using javascript, with setInterval) once that component becomes visible.

I haven't looked at the code since I posted this (gave up on the animation in the interest of deadlines), but I will take a look at it again tonight and elaborate the issue.

from react-visibility-sensor.

ihsansatriawan avatar ihsansatriawan commented on September 23, 2024

maybe you can filter with isVisible === true because in render, isVisible is false in my case

from react-visibility-sensor.

joshwnj avatar joshwnj commented on September 23, 2024

@JadSayegh can you tell us a little more about what you're hoping to do with this example?

from react-visibility-sensor.

g-a-v-i-n avatar g-a-v-i-n commented on September 23, 2024

This is happening to me as well.

from react-visibility-sensor.

rjacobs-r7 avatar rjacobs-r7 commented on September 23, 2024

This still seems to be affecting me on v3.10.1.
onChange is getting called when component scrolls out of viewport, which triggers an action/reducer, state gets mapped to a prop, component gets rerendered... and onChange gets called with true again. After this onChange no longer gets triggered when scrolling the component in/out of the viewport.

from react-visibility-sensor.

williamboman avatar williamboman commented on September 23, 2024

What about not updating state if the current visibility state is the same as the "new" visibility state?

class MyComponent extends Component {

   onChange = (isVisible) => {
       this.setState(prevState => {
           if (prevState.isVisible === isVisible) {
               return null
           }
           return {
               isVisible: isVisible,
               visCount: prevState.visCount + 1,
           }
       })
   }

   render(){
       return <div><VisibilitySensor onChange={this.onChange} /></div>
   }
}

from react-visibility-sensor.

williamboman avatar williamboman commented on September 23, 2024

This still seems to be affecting me on v3.10.1.
onChange is getting called when component scrolls out of viewport, which triggers an action/reducer, state gets mapped to a prop, component gets rerendered... and onChange gets called with true again. After this onChange no longer gets triggered when scrolling the component in/out of the viewport.

This might be the same issue I'm having in #102. I've opened #103 that fixes this.

from react-visibility-sensor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.