feat: add typewriter effect

This commit is contained in:
2025-07-15 06:22:31 +00:00
parent f3c4b3b33e
commit 4a9e275fa8

View File

@@ -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 (
<div className="App">
{loading ? <p>Loading...</p> : <p>{bodyText}</p>}
{loading ? <p>Loading...</p> : <p>{visibleText}</p>}
</div>
);
}