Skip to content

Commit

Permalink
Attempt 2 to add typewriter
Browse files Browse the repository at this point in the history
  • Loading branch information
iancheung0202 authored Nov 22, 2024
1 parent c20cd46 commit 94c0f2d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/app/(landing)/Heading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ export default function Heading() {
const typedRef = useRef<HTMLSpanElement>(null);

useEffect(() => {
// Dynamic script loader for Typed.js
const script = document.createElement("script");
script.src = "https://cdn.jsdelivr.net/npm/[email protected]";
script.async = true;

script.onload = () => {
if (typeof window.Typed !== "undefined" && typedRef.current) {
const typed = new window.Typed(typedRef.current, {
if (typedRef.current && typeof window.Typed !== "undefined") {
const typed = new (window as any).Typed(typedRef.current, {
strings: [
"Make, Build, Create & Learn.",
"It’s GunnHacks 11.0.",
Expand All @@ -55,13 +54,15 @@ export default function Heading() {
loop: true,
});

return () => typed.destroy(); // Cleanup on unmount
// Cleanup Typed instance on component unmount
return () => typed.destroy();
}
};

document.body.appendChild(script);

return () => {
// Clean up script
document.body.removeChild(script);
};
}, []);
Expand Down

0 comments on commit 94c0f2d

Please sign in to comment.