Sha256: e5b64b69e61c27cbcb657de26951f4fc066bfd36ef0c5bf5ad60718d1880f9e4

Contents?: true

Size: 588 Bytes

Versions: 1027

Compression:

Stored size: 588 Bytes

Contents

import { debounce } from 'lodash'
import { useCallback, useMemo, useState } from 'react'

export default function useVisibility(initialState = false) {
  const [visible, setVisible] = useState(initialState)
  const hide = useCallback(() => setVisible(false), [])
  const show = useCallback(({ afterDelay = 0 } = {}) => {
    debounce(() => setVisible(true), afterDelay)()
  }, [])
  const toggle = useCallback(() => setVisible((current) => !current), [])

  return useMemo(
    () => ({
      hide,
      show,
      toggle,
      visible,
    }),
    [hide, show, toggle, visible]
  )
}

Version data entries

1,027 entries across 1,027 versions & 1 rubygems

Version Path
playbook_ui-12.9.0 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-12.8.0.pre.alpha.PLAY625phonenumberdark301 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-12.8.0.pre.alpha.PLAY625phonenumberdark300 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-12.8.0.pre.alpha.PLAY649mapkitstyles299 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-12.8.0.pre.alpha.PLAY645typescriptprogresstep298 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-12.8.0.pre.alpha.PLAY645typescriptprogresstep297 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-12.8.0.pre.alpha.rubyandnpmalpharelease296 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-12.8.0.pre.alpha.rubyandnpmalpharelease295 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-12.8.0.pre.alpha.rubyandnpmalpharelease294 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-12.8.0 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-12.7.1.pre.alpha.rubyandnpmalpharelease293 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-12.7.1.pre.alpha.rubyandnpmalpharelease292 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-12.7.1.pre.alpha.rubyandnpmalpharelease291 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-12.7.1.pre.alpha.alpharubyrelease281 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-12.7.1.pre.alpha.menu2 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-12.7.1.pre.alpha.menu1 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-12.7.1 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-12.7.0 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-12.6.0.pre.alpha.sectionseparator1 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-12.6.0.pre.alpha.menuyml1 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js