added useRef, useContext examples
This commit is contained in:
34
react_alap/mai/src/Adatlekero.js
Normal file
34
react_alap/mai/src/Adatlekero.js
Normal 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;
|
||||
Reference in New Issue
Block a user