UNPKG

echarts-for-react-fc

Version:

Using ECharts in React, encapsulating it within a functional component, and providing a hook for consumers to consume.

42 lines (41 loc) 912 B
import { jsx as c, Fragment as d } from "react/jsx-runtime"; import { useState as p, useMemo as s } from "react"; import { createPortal as T } from "react-dom"; import { throttle as h } from "lodash-es"; const g = ({ tooltipDom: o, component: t }) => /* @__PURE__ */ c(d, { children: o && T(t, o) }), v = (o) => { const { component: t, needThrottle: r = !1, throttleTime: e = 100 } = o, [n] = p( () => document.createElement("div") ), [i, l] = p(), a = s(() => { const m = (u) => { l(typeof t == "function" ? t(u) : t); }; return r ? h( m, e, { leading: e !== 0, trailing: !0 } ) : m; }, [t, r, e]), f = s( () => /* @__PURE__ */ c( g, { tooltipDom: n, component: i } ), [i, n] ); return { tooltipDom: n, createTooltip: a, tooltipRender: f }; }; export { v as default };