ReactJS: add loading state
- use 8081 port for talking to SpringBoot (as 8080 occupied by Corda)
This commit is contained in:
parent
55d086bbe2
commit
db3cf0ee29
@ -17,7 +17,7 @@
|
||||
"test": "react-scripts test",
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
"proxy": "http://localhost:8080",
|
||||
"proxy": "http://localhost:8081",
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"react-app",
|
||||
|
@ -3,24 +3,25 @@ import React, { useState, useEffect } from 'react';
|
||||
|
||||
function App() {
|
||||
|
||||
const [joke, setJoke] = useState([]);
|
||||
const [joke, setJoke] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
fetch('/api/badjokes')
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
console.log(data.joke);
|
||||
setJoke(data.joke);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err.message);
|
||||
});
|
||||
fetch('/api/badjokes')
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
console.log(data.joke);
|
||||
setJoke(data.joke);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err.message);
|
||||
});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="App">
|
||||
<header className="App-header">
|
||||
<p>
|
||||
Here is your joke: {joke}
|
||||
<p>
|
||||
Here is your joke: {joke ? <span>{joke}</span> : <span>Loading...</span>}
|
||||
</p>
|
||||
</header>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user