ReactJS: add loading state

- use 8081 port for talking to SpringBoot (as 8080 occupied by Corda)
This commit is contained in:
djmil 2023-08-19 19:59:55 +02:00
parent 55d086bbe2
commit db3cf0ee29
2 changed files with 14 additions and 13 deletions

View File

@ -17,7 +17,7 @@
"test": "react-scripts test", "test": "react-scripts test",
"eject": "react-scripts eject" "eject": "react-scripts eject"
}, },
"proxy": "http://localhost:8080", "proxy": "http://localhost:8081",
"eslintConfig": { "eslintConfig": {
"extends": [ "extends": [
"react-app", "react-app",

View File

@ -3,7 +3,8 @@ import React, { useState, useEffect } from 'react';
function App() { function App() {
const [joke, setJoke] = useState([]); const [joke, setJoke] = useState(null);
useEffect(() => { useEffect(() => {
fetch('/api/badjokes') fetch('/api/badjokes')
.then((response) => response.json()) .then((response) => response.json())
@ -20,7 +21,7 @@ function App() {
<div className="App"> <div className="App">
<header className="App-header"> <header className="App-header">
<p> <p>
Here is your joke: {joke} Here is your joke: {joke ? <span>{joke}</span> : <span>Loading...</span>}
</p> </p>
</header> </header>
</div> </div>