Coder Social home page Coder Social logo

onderonur / react-intersection-observer-hook Goto Github PK

View Code? Open in Web Editor NEW
65.0 1.0 7.0 4.57 MB

React hook to use IntersectionObserver declaratively.

Home Page: https://onderonur.github.io/react-intersection-observer-hook/

License: MIT License

HTML 2.69% TypeScript 83.60% JavaScript 13.27% Shell 0.44%
react-hooks visibility typescript react intersection-observer intersectionobserver reactjs

react-intersection-observer-hook's People

Contributors

dependabot[bot] avatar onderonur avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

react-intersection-observer-hook's Issues

Create-React-App testing fails

Hi there,

I have a react component that uses your react-infinite-scroll-hook and couldn't get tests for it to work properly. I would always get the following error:

ReferenceError: IntersectionObserver is not defined

Here is a minimal reproduction example. I also used intersetion-observer polyfill as a workaround for this issue and it seems to work fine. Just toggle the first import statement in App.js.

By the way, when I tried testing that component with plain @testing-library/react, it worked just fine.

Intersection observer does not update if config changes

Hi there! First of all thank you for this very useful lib; I used it a few times now and usually it works as expected. But I had a scenario where i wanted to update the rootMargin upon window.resize. Unfortunately the current implementation does not update the observer instance when the config of the observer changes.

Before I suggest a possible solution to this problem I wanted to ask if you are at all interested to solve this problem—or if you maybe took this into consideration already when building the current implementation.

Dealing with multiple child refs

Hi, thanks for creating this!

So I want to track a list of items (chat messages in an infinite scrolling list) in a custom scrollable div. If I understand correctly, this means I should use rootRef for the parent. However, since I have multiple children, I need a ref for every chilld, but only one for the parent. Does this library support this? I tried setting the root in the options (passing the parentRef), but for some reason that does not work.

No visibility tracking with react 18

Hi,

I know it's a bit early to dive into React 18 since it's only in alpha but I have to use it because of relay routing and concurrent mode.
Moving to this alpha version happened to break useInfiniteScroll. With (painful) debugging in console, the further I could go is in this package and I saw that the IntersectionObserver callback was never called.
I tried to use this package directly instead of useInfiniteScroll, see if I would have better luck but it didn't work either.

I was wondering if React concurrent mode completely broke with IntersectionObserver (since ReactDOM initialization is done in a different way now) but following this tutorial, I was able to put it back on track. I had to remove the ref from the dependencies of useEffect to make it work though, leading to delete / recreate my observer on every render. Twice actually, because of "double render effect", but at least it works.

I don't know exactly what's going on with intersectionObserverHook but just so you know, it breaks.

Have a good one ;)

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.