Closed paulinabjacykowska closed 1 year ago
What do you think about creating a custom hook like:
import { useHistory } from '@docusaurus/router'; import { useEffect } from 'react'; const handleNavbarScroll = () => { const navbar = document.querySelector('.navbar'); if (navbar) { navbar.classList.toggle('scroll', window.scrollY > window.innerHeight - 60); } }; const handleNavbarBackground = () => { const navbar = document.querySelector('.navbar'); if (navbar) { navbar.classList.add('homepage-navbar'); } }; export const useNavbarStyles = () => { const history = useHistory(); useEffect(() => { history.location.pathname === '/' && handleNavbarBackground(); }, [history.location.pathname]); useEffect(() => { window.addEventListener('scroll', handleNavbarScroll); return () => { window.removeEventListener('scroll', handleNavbarScroll); }; }, []); };
?
We would have all of the logic in a single file and we wouldn't pollute the
LayoutBase
component with additional logic. Instead of it, we'll simply call one hook.
I think this looks extremely nice! 🚀 To be honest I learned so much about good practices and ideas to implement in a React project since I am on Forminer, thanks! 🙌
I think this looks extremely nice! rocket To be honest I learned so much about good practices and ideas to implement in a React project since I am on Forminer, thanks! raised_hands
So happy to hear that! :smile:
In this PR I added:
docs
ordemo
page, the navbar has white background from the beginning