2023-08-13 15:31:47 +02:00
|
|
|
import './App.css';
|
|
|
|
import React, { useState, useEffect } from 'react';
|
|
|
|
|
|
|
|
function App() {
|
|
|
|
|
2023-08-19 19:59:55 +02:00
|
|
|
const [joke, setJoke] = useState(null);
|
|
|
|
|
2023-08-13 15:31:47 +02:00
|
|
|
useEffect(() => {
|
2023-08-19 19:59:55 +02:00
|
|
|
fetch('/api/badjokes')
|
|
|
|
.then((response) => response.json())
|
|
|
|
.then((data) => {
|
|
|
|
console.log(data.joke);
|
|
|
|
setJoke(data.joke);
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
console.log(err.message);
|
|
|
|
});
|
2023-08-13 15:31:47 +02:00
|
|
|
}, []);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="App">
|
|
|
|
<header className="App-header">
|
2023-08-19 19:59:55 +02:00
|
|
|
<p>
|
|
|
|
Here is your joke: {joke ? <span>{joke}</span> : <span>Loading...</span>}
|
2023-08-13 15:31:47 +02:00
|
|
|
</p>
|
|
|
|
</header>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default App;
|