ReactJS: user managment

This commit is contained in:
djmil 2023-08-21 18:05:19 +02:00
parent fa2e4b0669
commit b0e2f0e25b

View File

@ -3,14 +3,15 @@ import React, { useState, useEffect } from 'react';
function App() { function App() {
const [joke, setJoke] = useState(null); const [activeGames, setActiveGames] = useState(null);
useEffect(() => { useEffect(() => {
fetch('/api/badjokes') fetch('/api/activegames')
.then((response) => response.json()) .then((response) => response.json())
.then((data) => { .then((games) => {
console.log(data.joke); console.log(games.ActiveGames.length);
setJoke(data.joke); console.log("games: " +games.ActiveGames);
setActiveGames(games.ActiveGames);
}) })
.catch((err) => { .catch((err) => {
console.log(err.message); console.log(err.message);
@ -21,7 +22,7 @@ function App() {
<div className="App"> <div className="App">
<header className="App-header"> <header className="App-header">
<p> <p>
Here is your joke: {joke ? <span>{joke}</span> : <span>Loading...</span>} Here is list of your active games: {activeGames ? <span>{activeGames}</span> : <span>Loading...</span>}
</p> </p>
</header> </header>
</div> </div>