Skip to content

Commit 23a0003

Browse files
authored
Merge pull request #168 from alecb6/fix-metallic-paint-issue
fix: MetallicPaint import texts, and useState management
2 parents 0ef8b0f + aef625e commit 23a0003

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/constants/code/Animations/metallicPaintCode.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import tsTailwind from '@ts-tailwind/Animations/MetallicPaint/MetallicPaint.tsx?
88

99
export const metallicPaint = {
1010
...(generateCliCommands('Animations/MetallicPaint')),
11-
usage: `import MetallicPaint, { parseLogoImage } from "./MetallicPaint";'
11+
usage: `import MetallicPaint, { parseLogoImage } from "./MetallicPaint";
1212
import { useState, useEffect } from 'react';
1313
1414
// replace with your own SVG
@@ -17,36 +17,38 @@ import { useState, useEffect } from 'react';
1717
import logo from '../../assets/logos/react-bits-solid-black.svg';
1818
1919
const Component = () => {
20-
const [imageData, setImageData] = useState(null);
20+
const [imageData, setImageData] = useState<ImageData | null>(null);
2121
2222
useEffect(() => {
2323
async function loadDefaultImage() {
2424
try {
2525
const response = await fetch(logo);
2626
const blob = await response.blob();
2727
const file = new File([blob], "default.png", { type: blob.type });
28-
const { imageData } = await parseLogoImage(file);
29-
setImageData(imageData);
28+
29+
const parsedData = await parseLogoImage(file);
30+
setImageData(parsedData?.imageData ?? null);
31+
3032
} catch (err) {
3133
console.error("Error loading default image:", err);
3234
}
3335
}
34-
36+
3537
loadDefaultImage();
3638
}, []);
3739
3840
return (
3941
<div style={{ width: '100%', height: '100vh' }}>
4042
<MetallicPaint
41-
imageData={imageData}
43+
imageData={imageData ?? new ImageData(1, 1)}
4244
params={{ edge: 2, patternBlur: 0.005, patternScale: 2, refraction: 0.015, speed: 0.3, liquid: 0.07 }}
4345
/>
4446
</div>
4547
);
4648
}`,
47-
code,
48-
css,
49-
tailwind,
50-
tsCode,
51-
tsTailwind
52-
}
49+
code,
50+
css,
51+
tailwind,
52+
tsCode,
53+
tsTailwind
54+
};

0 commit comments

Comments
 (0)