How to use the react-use.useEvent function in react-use

To help you get started, we’ve selected a few react-use examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github EnixCoda / Gitako / src / components / SideBar.tsx View on Github external
function attachCopyFileButton() {
      if (configContext.val.copyFileButton) return DOMHelper.attachCopyFileBtn() || undefined // for the sake of react effect
    },
    [configContext.val.copyFileButton],
  )
  React.useEffect(attachCopyFileButton, [configContext.val.copyFileButton])
  useEvent('pjax:complete', attachCopyFileButton, window)

  const attachCopySnippetButton = React.useCallback(
    function attachCopySnippetButton() {
      if (configContext.val.copySnippetButton) return DOMHelper.attachCopySnippet() || undefined // for the sake of react effect
    },
    [configContext.val.copySnippetButton],
  )
  React.useEffect(attachCopySnippetButton, [configContext.val.copySnippetButton])
  useEvent('pjax:complete', attachCopySnippetButton, window)

  // init again when setting new accessToken
  useDidUpdate(() => {
    props.init()
  }, [accessToken])

  const {
    errorDueToAuth,
    metaData,
    treeData,
    baseSize,
    error,
    shouldShow,
    showSettings,
    logoContainerElement,
    toggleShowSideBar,
github EnixCoda / Gitako / src / components / SideBar.tsx View on Github external
}),
        )
      }
    },
    [props.metaData?.branchName, configContext.val.intelligentToggle],
  )
  useEvent('pjax:complete', updateSideBarVisibility, window)

  const attachCopyFileButton = React.useCallback(
    function attachCopyFileButton() {
      if (configContext.val.copyFileButton) return DOMHelper.attachCopyFileBtn() || undefined // for the sake of react effect
    },
    [configContext.val.copyFileButton],
  )
  React.useEffect(attachCopyFileButton, [configContext.val.copyFileButton])
  useEvent('pjax:complete', attachCopyFileButton, window)

  const attachCopySnippetButton = React.useCallback(
    function attachCopySnippetButton() {
      if (configContext.val.copySnippetButton) return DOMHelper.attachCopySnippet() || undefined // for the sake of react effect
    },
    [configContext.val.copySnippetButton],
  )
  React.useEffect(attachCopySnippetButton, [configContext.val.copySnippetButton])
  useEvent('pjax:complete', attachCopySnippetButton, window)

  // init again when setting new accessToken
  useDidUpdate(() => {
    props.init()
  }, [accessToken])

  const {
github EnixCoda / Gitako / src / components / SideBar.tsx View on Github external
[props.disabled, configContext.val.shortcut],
  )

  const updateSideBarVisibility = React.useCallback(
    function updateSideBarVisibility() {
      if (configContext.val.intelligentToggle === null) {
        props.setShouldShow(
          URLHelper.isInCodePage({
            branchName: props.metaData?.branchName,
          }),
        )
      }
    },
    [props.metaData?.branchName, configContext.val.intelligentToggle],
  )
  useEvent('pjax:complete', updateSideBarVisibility, window)

  const attachCopyFileButton = React.useCallback(
    function attachCopyFileButton() {
      if (configContext.val.copyFileButton) return DOMHelper.attachCopyFileBtn() || undefined // for the sake of react effect
    },
    [configContext.val.copyFileButton],
  )
  React.useEffect(attachCopyFileButton, [configContext.val.copyFileButton])
  useEvent('pjax:complete', attachCopyFileButton, window)

  const attachCopySnippetButton = React.useCallback(
    function attachCopySnippetButton() {
      if (configContext.val.copySnippetButton) return DOMHelper.attachCopySnippet() || undefined // for the sake of react effect
    },
    [configContext.val.copySnippetButton],
  )