https://echarts.apache.org/zh/api.html#echartsInstance.resize
image.png

react-resize-detector

https://github.com/maslianok/react-resize-detector

  1. yarn add react-resize-detector
  2. import { useResizeDetector } from 'react-resize-detector';
  3. const CustomComponent = () => {
  4. const { width, height, ref } = useResizeDetector();
  5. return <div ref={ref}>{`${width}x${height}`}</div>;
  6. };
  7. // ref
  8. const CustomComponent = () => {
  9. const targetRef = useRef();
  10. const { width, height } = useResizeDetector({ targetRef });
  11. return <div ref={targetRef}>{`${width}x${height}`}</div>;
  12. };

image.png

resize-detector

https://www.npmjs.com/package/resize-detector

element-resize-detector

https://github.com/wnr/element-resize-detector

  1. yarn add element-resize-detector
  • listenTo(element, listener) or listenTo(options, element, listener)
  • removeListener(element, listener)
  • removeAllListeners(element)
  • uninstall(element)
  • initDocument(document)

size-sensor

  1. yarn add size-sensor
  2. import { bind, clear } from 'size-sensor';
  3. // bind the event on element, will get the `unbind` function
  4. const unbind1 = bind(document.querySelector('.container'), element => {
  5. // do what you want to to.
  6. });
  7. const unbind2 = bind(document.querySelector('.container'), element => {
  8. // do what you want to to.
  9. });
  10. // if you want to cancel bind event.
  11. unbind1();