Sha256: e5b64b69e61c27cbcb657de26951f4fc066bfd36ef0c5bf5ad60718d1880f9e4

Contents?: true

Size: 588 Bytes

Versions: 889

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

889 entries across 889 versions & 1 rubygems

Version Path
playbook_ui-14.8.0.pre.alpha.PLAY1680newwidthprop4661 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-14.8.0.pre.alpha.PLAY1658tanstackbump4657 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-14.8.0.pre.alpha.PLAY1649rolloutheightglobalprops4635 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-14.9.0.pre.rc.8 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-14.8.0.pre.alpha.PLAY1598floatinguiupgrade4617 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-14.9.0.pre.rc.7 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-14.9.0.pre.rc.6 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-14.9.0.pre.rc.5 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-14.8.0.pre.alpha.pbntr661createstickyleftprop4612 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-14.8.0.pre.alpha.play1648heightglobalprops4606 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-14.9.0.pre.rc.4 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-14.9.0.pre.rc.3 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-14.9.0.pre.rc.2 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-14.8.0.pre.alpha.revert3916revert3893PBNTR667railstypeaheadformintegration4567 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-14.8.0.pre.alpha.revert3916revert3893PBNTR667railstypeaheadformintegration4565 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-14.8.0.pre.alpha.PLAY1598floatinguiupgrade4563 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-14.8.0.pre.alpha.play1648heightglobalprops4559 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-14.9.0.pre.rc.1 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-14.8.0.pre.alpha.PLAY16254545 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js
playbook_ui-14.8.0.pre.alpha.PLAY1615movenegativetoleftofcurrencysign4543 app/pb_kits/playbook/pb_lightbox/hooks/useVisibility.js