vazco / forminer

Vazco Form Builder Docs
https://forminer.com
1 stars 0 forks source link

FB-333-fix-navbar #58

Closed paulinabjacykowska closed 1 year ago

paulinabjacykowska commented 1 year ago

In this PR I added:

paulinabjacykowska commented 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! 🙌

mkaliszewski commented 1 year ago

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: