feat: render chars in list items
This commit is contained in:
@@ -1,19 +1,24 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
import { fetchBodyText } from "./api/fetchBodyText";
|
import { fetchBodyText } from "./api/fetchBodyText";
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
|
const hasLoaded = useRef(false);
|
||||||
const [bodyText, setBodyText] = useState("");
|
const [bodyText, setBodyText] = useState("");
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [visibleText, setVisibleText] = useState("");
|
const [visibleText, setVisibleText] = useState("");
|
||||||
|
|
||||||
// Call to load flag
|
// Call to load flag
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (hasLoaded.current) return;
|
||||||
|
hasLoaded.current = true;
|
||||||
|
|
||||||
async function load() {
|
async function load() {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const text = await fetchBodyText();
|
const text = await fetchBodyText();
|
||||||
setBodyText(text);
|
setBodyText(text);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
load();
|
load();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -38,7 +43,15 @@ function App() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="App">
|
<div className="App">
|
||||||
{loading ? <p>Loading...</p> : <p>{visibleText}</p>}
|
{loading ? (
|
||||||
|
<p>Loading...</p>
|
||||||
|
) : (
|
||||||
|
<ul>
|
||||||
|
{visibleText.split("").map((char, index) => (
|
||||||
|
<li key={index}>{char}</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user