screenshot-to-code/frontend/src/components/CodePreview.tsx
2023-11-14 18:21:57 -05:00

28 lines
545 B
TypeScript

import { useRef, useEffect } from "react";
interface Props {
code: string;
}
function CodePreview({ code }: Props) {
const scrollRef = useRef<HTMLDivElement>(null);
useEffect(() => {
if (scrollRef.current) {
scrollRef.current.scrollLeft = scrollRef.current.scrollWidth;
}
}, [code]);
return (
<div
ref={scrollRef}
className="w-full px-2 bg-black text-green-400 whitespace-nowrap flex
overflow-x-auto font-mono text-[10px] my-4"
>
{code}
</div>
);
}
export default CodePreview;