summaryrefslogtreecommitdiffstats
path: root/packages/excalidraw/components/SVGLayer.tsx
blob: 667b89ab7efb996a9b29860f77f082099c2c624c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { useEffect, useRef } from "react";
import type { Trail } from "../animated-trail";

import "./SVGLayer.scss";

type SVGLayerProps = {
  trails: Trail[];
};

export const SVGLayer = ({ trails }: SVGLayerProps) => {
  const svgRef = useRef<SVGSVGElement | null>(null);

  useEffect(() => {
    if (svgRef.current) {
      for (const trail of trails) {
        trail.start(svgRef.current);
      }
    }

    return () => {
      for (const trail of trails) {
        trail.stop();
      }
    };
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, trails);

  return (
    <div className="SVGLayer">
      <svg ref={svgRef} />
    </div>
  );
};