summaryrefslogtreecommitdiff
path: root/src/core/hooks/useSidebar.js
blob: c463fd81809afead554d45ff823fc81026a0fc85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import useActive from './useActive'
import SidebarComponent from '../components/elements/Sidebar/Sidebar'
import { useEffect } from 'react'

const useSidebar = () => {
  const { active, activate, deactivate } = useActive()

  useEffect(() => {
    if (active) {
      document.querySelector('html, body').classList.add('overflow-hidden')
    } else {
      document.querySelector('html, body').classList.remove('overflow-hidden')
    }
  }, [active])

  return {
    open: activate,
    Sidebar: <SidebarComponent active={active} close={deactivate} />
  }
}

export default useSidebar