How to use the @umijs/hooks.useEventListener function in @umijs/hooks

To help you get started, we’ve selected a few @umijs/hooks 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 pingcap / tidb-dashboard / ui / lib / components / BaseSelect / index.tsx View on Github external
const dropdownOverlayRef = useRef(null)
  const containerRef = useRef(null)

  const overlay = useMemo(() => {
    return (
      <div>
        {dropdownRender()}
      </div>
    )
  }, [dropdownRender, overlayClassName, handleOverlayMouseDown])

  useEventListener('mousedown', (ev: MouseEvent) =&gt; {
    // Close the dropdown if click outside
    if (!dropdownVisible) {
      return
    }
    const hitElements = [dropdownOverlayRef.current, containerRef.current]
    if (
      hitElements.every(
        (e) =&gt;
          !e ||
          !ev.target ||
          (!e.contains(ev.target as HTMLElement) &amp;&amp; e !== ev.target)
      )
    ) {
      setDropdownVisible(false)
    }
  })
github pingcap / tidb-dashboard / ui / lib / apps / KeyViz / heatmap / index.tsx View on Github external
const container = divRef.current
        chart.current = await heatmapChart(
          d3.select(container),
          props.data,
          props.dataTag,
          props.onBrush,
          props.onZoom
        )
        props.onChartInit(chart.current)
        updateChartSize()
      }
    }
    init()
  }, [props, props.data, props.dataTag])

  useEventListener('resize', () =&gt; {
    updateChartSize()
  })

  return <div>
}
</div>
github pingcap / tidb-dashboard / ui / lib / components / TopLoadingBar / index.tsx View on Github external
const useLoadingBar = () =&gt; {
  const loadingBar = useRef()
  useEventListener('single-spa:before-routing-event', () =&gt;
    loadingBar.current.continuousStart()
  )
  useEventListener('single-spa:routing-event', () =&gt;
    loadingBar.current.complete()
  )

  return loadingBar
}
github pingcap / tidb-dashboard / ui / lib / components / TopLoadingBar / index.tsx View on Github external
const useLoadingBar = () =&gt; {
  const loadingBar = useRef()
  useEventListener('single-spa:before-routing-event', () =&gt;
    loadingBar.current.continuousStart()
  )
  useEventListener('single-spa:routing-event', () =&gt;
    loadingBar.current.complete()
  )

  return loadingBar
}