@dank-inc/react-sketchy
Version:
React Wrapper component for sketchy!
27 lines (26 loc) • 1.07 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { useEffect, useRef } from "react";
import { createParams, loadSketch, } from "@dank-inc/sketchy";
export var ReactSketchy = function (_a) {
var sketch = _a.sketch, dimensions = _a.dimensions, className = _a.className, animate = _a.animate, timeOffset = _a.timeOffset, elRef = _a.elRef;
var ref = useRef(null);
useEffect(function () {
if (!ref.current)
return;
var el = (elRef === null || elRef === void 0 ? void 0 : elRef.current) || ref.current;
var params = loadSketch(sketch, createParams({
element: el,
dimensions: dimensions,
animate: animate,
timeOffset: timeOffset,
}));
return function () {
params.animated = false;
var child = el.firstChild;
child && el.removeChild(child);
};
}, [sketch, ref, elRef, dimensions, animate, timeOffset]);
if (elRef)
return null;
return _jsx("div", { className: className, ref: ref }, void 0);
};