Threshold not working useIntersectionObserver hook #968
-
Hi, I am not sure if I am doing something wrong as this has been a long coding session, and I might be overlooking an error I made, but I feel like I followed something similar than what's available on StackBlitz, yet my code is not running: Am I doing something wrong or is this feature just not working at the moment? Thank you! |
Beta Was this translation helpful? Give feedback.
Answered by
melloware
Jan 20, 2024
Replies: 1 comment 2 replies
-
I am looking at the source and it passes your options through to the IntersectionObserver. Not much magic going on here. import * as React from 'react';
export const useIntersectionObserver = (ref, options = {}) => {
const [isElementVisible, setIsElementVisible] = React.useState(false);
React.useEffect(() => {
if (!ref.current) return;
const observer = new IntersectionObserver(([entry]) => {
setIsElementVisible(entry.isIntersecting);
}, options);
observer.observe(ref.current);
return () => {
observer.disconnect();
};
}, [options, ref]);
return isElementVisible;
}; |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It is just a bug in PrimeReact's TypeScript def. I just submitted a PR to fix it for 10.4.0. See: primefaces/primereact#5810