Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The scrollPosition prop of HOC trackWindowScroll always return "null" #101

Open
huynlx opened this issue Apr 7, 2022 · 4 comments
Open

Comments

@huynlx
Copy link

huynlx commented Apr 7, 2022

Bug description
The scrollPosition prop of HOC trackWindowScroll always return "null". I think it should return a object {x,y} ?

@huynlx huynlx changed the title the scrollPosition prop of HOC trackWindowScroll always return "null" The scrollPosition prop of HOC trackWindowScroll always return "null" Apr 7, 2022
@Aljullu
Copy link
Owner

Aljullu commented Apr 7, 2022

Hi @Huynh12345678, thanks for opening this issue! Can you try passing useIntersectionObserver: false as a prop? If it's set to true and the browser supports intersection observer, trackWindowScroll will default to null:

const scrollPosition = this.useIntersectionObserver
? null
: this.state.scrollPosition;

@huynlx
Copy link
Author

huynlx commented Apr 7, 2022

Hi @Huynh12345678, thanks for opening this issue! Can you try passing useIntersectionObserver: false as a prop? If it's set to true and the browser supports intersection observer, trackWindowScroll will default to null:

const scrollPosition = this.useIntersectionObserver
? null
: this.state.scrollPosition;

Oh, so i don't necessarily use trackWindowScroll if the browser supports intersection observer ?

@huynlx
Copy link
Author

huynlx commented Apr 7, 2022

Hi @Huynh12345678, thanks for opening this issue! Can you try passing useIntersectionObserver: false as a prop? If it's set to true and the browser supports intersection observer, trackWindowScroll will default to null:

const scrollPosition = this.useIntersectionObserver
? null
: this.state.scrollPosition;

And how to setState loaded from true to false when changing img src in the same component ?
Because i want it to rerun the effect when changing the img src on the same component

@Aljullu
Copy link
Owner

Aljullu commented Apr 10, 2022

Oh, so i don't necessarily use trackWindowScroll if the browser supports intersection observer ?

If you only want to use LazyLoadImage or LazyLoadComponent, it shouldn't be necessary. react-lazy-load-image-component tries to use the native Intersection Observer because it's more performant.

trackWindowScroll is still there for compatibility with old browsers or in case you need to manually have access to the window scroll position.

And how to setState loaded from true to false when changing img src in the same component ?
Because i want it to rerun the effect when changing the img src on the same component

I would try setting a different key prop to the component, so React remounts it.

Hope it helps! 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants