We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

EmpCaptain • 5 years ago

I keep getting the Cannot read property getBoundingClientRect of null, even though i set a div to have a ref of StickyRef

KoduĊ› • 5 years ago

Same problem here. Found a little workaround here:

const handleScroll = () => {
if (stickyRef.current) {
window.pageYOffset > stickyRef.current.getBoundingClientRect().bottom
? setSticky(true)
: setSticky(false);
}
};

Ibrahima Ndaw • 5 years ago

I have fixed the bugs and also updated the sticky effect with a custom hook.

Sarath Nagesh • 5 years ago

scroll listener was not getting removed when component was unmounted. I used useCallback for fixing it:

const scrollHandler = useCallback(() => {
debounce(handleScroll())
}, [])

useEffect(() => {
if (location.pathname === '/') {
window.addEventListener("scroll", scrollHandler)
return () => {
window.removeEventListener("scroll", scrollHandler)
}
}
}, [debounce, handleScroll]);

Nishant Kumar Bhardwaj • 5 years ago

I simply used the bootstrap property, fixed="top"

<navbar id="nav" fixed="top" expand="lg" bg="light" variant="light">

sunbeamrapier • 5 years ago

Hi mate. Nice idea but it is a bit of a muddle now... The original code (as per this post) didn't run - some issue with the rendering of Welcome.js - but there isn't a render in that file. ??

The latest build from your github account has additional require statements in the index.js module. You will need to update this post to include the extra npm i express/next/path/fs modules (I assume that is what the missing module errors mean - but I am a newbie at this!

After installing the extra modulesmpm i get an error "./src/index.js Error: ENOENT: no such file or directory, open '/Users/Srjones/0_W4web/w4web/react-sticky-navbar/src/index.js'

I moved this back to the first level folder - now I get a missing module 'cors'

I installed cors - the app compiled but renders just this error: 'Cannot get /'

There is no index.html file in this project... Even if I add one I still get the same error

This is the third navbar code I have tried today - none of them work!

any suggestions would be welcomed - I really don't want to use bootstrap if I can help it...

Stag View • 5 years ago
Jelena Dimitrijevski • 5 years ago
Ibrahima Ndaw • 5 years ago

This error is related to the `ref`, the element is not selected, try to check if it refers to the element.

Guest • 5 years ago
Ibrahima Ndaw • 5 years ago

Can you please share a link to your code?