added useRef, useContext examples

This commit is contained in:
szabomarton
2025-01-17 09:17:41 +01:00
parent 31d0780080
commit 9c5ca86086
26 changed files with 114 additions and 12 deletions

View File

@@ -0,0 +1,34 @@
import React, {useState, useEffect} from "react";
function Adatlekero(){
let [adatok, setAdatok] = useState(null);
useEffect(
() => {
async function lekeres() {
try{
let response = await fetch("https://jsonplaceholder.typicode.com/posts");
let data = await response.json();
setAdatok(data);
} catch (error){
console.error('Hiba történt: ', error);
}
}
lekeres();
}
);
if (!adatok) {
return <p>Adatok betöltése ...</p>;
}
return (
<ol>
{adatok.map((adat) => (
<li key={adat.id}>{adat.title}</li>
))}
</ol>
)
}
export default Adatlekero;