Skip to content

Drop in a screenshot and convert it to clean code (HTML/Tailwind/React/Vue)

Python

Optimize thumbnail updates for better performance

Abi Rajaa7f9c20b451c
diff --git a/frontend/src/components/variants/Variants.tsx b/frontend/src/components/variants/Variants.tsx
index 12183496..d2152a04 100644
--- a/frontend/src/components/variants/Variants.tsx
+++ b/frontend/src/components/variants/Variants.tsx
@@ -5,11 +5,13 @@ import { useThrottle } from "../../hooks/useThrottle";
interface VariantThumbnailProps {
code: string;
+ isSelected: boolean;
}
-function VariantThumbnail({ code }: VariantThumbnailProps) {
+function VariantThumbnail({ code, isSelected }: VariantThumbnailProps) {
const iframeRef = useRef<HTMLIFrameElement>(null);
- const throttledCode = useThrottle(code, 300);
+ // Selected variant updates every 300ms, non-selected every 2000ms
+ const throttledCode = useThrottle(code, isSelected ? 300 : 2000);
useEffect(() => {
const iframe = iframeRef.current;
@@ -159,7 +161,10 @@ function Variants() {
⌥{index + 1}
</span>
</div>
- <VariantThumbnail code={variant.code} />
+ <VariantThumbnail
+ code={variant.code}
+ isSelected={index === selectedVariantIndex}
+ />
{(variant.status === "cancelled" || variant.status === "error") && (
<div className="text-xs mt-1 flex items-center">
{variant.status === "cancelled" && (