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",
 | 
					    "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",
 | 
				
			||||||
 | 
				
			|||||||
@ -3,24 +3,25 @@ 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())
 | 
				
			||||||
        .then((data) => {
 | 
					      .then((data) => {
 | 
				
			||||||
           console.log(data.joke);
 | 
					        console.log(data.joke);
 | 
				
			||||||
           setJoke(data.joke);
 | 
					        setJoke(data.joke);
 | 
				
			||||||
        })
 | 
					      })
 | 
				
			||||||
        .catch((err) => {
 | 
					      .catch((err) => {
 | 
				
			||||||
           console.log(err.message);
 | 
					        console.log(err.message);
 | 
				
			||||||
        });
 | 
					      });
 | 
				
			||||||
  }, []);
 | 
					  }, []);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return (
 | 
					  return (
 | 
				
			||||||
    <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>
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user