Sha256: e5b64b69e61c27cbcb657de26951f4fc066bfd36ef0c5bf5ad60718d1880f9e4

Contents?: true

Size: 588 Bytes

Versions: 1110

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,110 entries across 1,110 versions & 1 rubygems

Version Path
playbook_ui-13.0.0.pre.alpha.PLAY966collapsiblenav41126 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-13.0.0.pre.alpha.salesbookmismatchingdate1120 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-12.39.0.pre.alpha.salesbookmismatchingdate1117 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-13.0.0 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-12.39.0.pre.alpha.PLAY966collapsiblenav41115 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-12.39.0.pre.alpha.salesbookmismatchingdate1114 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-12.39.0 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-12.38.0.pre.alpha.PBNTR78selectkitmultipleprop1094 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-12.38.0.pre.alpha.PLAY932removemomentqp1088 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-12.38.0.pre.alpha.PLAY966collapsiblenav41086 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-12.38.0.pre.alpha.audiencesalpha1083 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-12.38.0.pre.alpha.PLAY966collapsiblenav41082 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-12.38.0.pre.alpha.PLAYaddingdatapropselectkit1080 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-12.37.0.pre.alpha.PLAY951collapsiblenav31078 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-12.38.0.pre.alpha.playbook123801077 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-12.37.0.pre.alpha.PLAY951collapsiblenav31074 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-12.37.0.pre.alpha.PLAY951collapsiblenav31073 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-12.37.0.pre.alpha.PLAYaddingdatapropselectkit1071 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-12.38.0 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-12.37.0.pre.alpha.svgiconmethods1064 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js