From 4a9e275fa86e448d60f469b63cdf1cb50f0dac6f Mon Sep 17 00:00:00 2001 From: Giovani Rodriguez Date: Tue, 15 Jul 2025 06:22:31 +0000 Subject: [PATCH] feat: add typewriter effect --- typewriter/src/App.tsx | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/typewriter/src/App.tsx b/typewriter/src/App.tsx index 1ec4cdb..15bc454 100644 --- a/typewriter/src/App.tsx +++ b/typewriter/src/App.tsx @@ -4,7 +4,9 @@ import { fetchBodyText } from "./api/fetchBodyText"; function App() { const [bodyText, setBodyText] = useState(""); const [loading, setLoading] = useState(true); + const [visibleText, setVisibleText] = useState(""); + // Call to load flag useEffect(() => { async function load() { setLoading(true); @@ -15,9 +17,28 @@ function App() { load(); }, []); + // Typewriter effect + useEffect(() => { + if (!loading && bodyText) { + let index = 0; + const delay = 500; // 0.5ms per character + + const type = () => { + setVisibleText(bodyText.slice(0, index)); + index++; + if (index <= bodyText.length) { + setTimeout(type, delay); + } + }; + + type(); + } + }, [loading, bodyText]); + + return (
- {loading ?

Loading...

:

{bodyText}

} + {loading ?

Loading...

:

{visibleText}

}
); }