import { useState, useCallback } from 'react'

export const useToggle = (initialState = false) => {
  const [isOpen, setIsOpen] = useState(initialState)
  const open = useCallback(() => setIsOpen(true), [])
  const close = useCallback(() => setIsOpen(false), [])
  const toggle = useCallback(() => setIsOpen((state) => !state), [])
  return {
    close,
    isOpen,
    open,
    setIsOpen,
    toggle,
  }
}
