How to use the react-use.useLockBodyScroll function in react-use

To help you get started, we’ve selected a few react-use examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github blockstack / blockstack.org / components / header / index.js View on Github external
const Header = ({
  theme: headerTheme = defaultHeaderTheme,
  innerRef,
  ...rest
}) => {
  const [hovered, bind] = useHover()
  const [subnavVisible, setSubnavVisibility] = useState(null)

  const [items, setItems] = useState([])
  const [mobileMenuOpen, setMobileMenuState] = useState(false)
  const isMobile = useMedia(1)

  useLockBodyScroll(isMobile && mobileMenuOpen)

  const handleMenuToggle = () => {
    setMobileMenuState((s) => !s)
  }

  const handleSetItems = (i) => {
    const theItems =
      (subnavVisible &&
        navigation.find((item) => item.slug === subnavVisible).items) ||
      []
    setItems(theItems)
  }

  useEffect(() => {
    if (!isMobile) {
      if (subnavVisible && !hovered) {
github blockstack / blockstack.org / components / modal / index.js View on Github external
const Modal = ({ ...rest }) => {
  const { src, open, ref, handleClose } = useModalHooks()
  useLockBodyScroll(open)
  return (
github kyma-project / website / src / components / generic-documentation / render-engines / markdown / headers-toc / HeadersComponent.tsx View on Github external
export const HeadersNavigation: React.FunctionComponent = ({
  enableSmoothScroll = false,
  children = null,
}) => {
  const { showMobileRightNav } = useContext(GenericDocsContext);
  const headersWrapperRef = useRef();
  const [locked, toggleLocked] = useToggle(false);
  useLockBodyScroll(locked);

  const onMouseEnter = () => {
    toggleLocked(true);
  };

  const onMouseLeave = () => {
    toggleLocked(false);
  };

  return (