Last active
September 15, 2020 23:20
-
-
Save MattSegal/66570f4d80af7f3a92e8d18f3f87bc0a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from 'react' | |
import Header from './components/Header.js' | |
import Game from './components/Game.js' | |
import LeaderBoard from './components/LeaderBoard.js' | |
import Spinner from './components/Spinner.js' | |
// Don't hardcode strings, use constants | |
const DEFAULT_NAME = 'jeff' | |
export default function App(){ | |
const [opponentName, setOpponentName] = useState(DEFAULT_NAME) | |
const [loading, setLoading] = useState(false) | |
// Fine, but could be shorter | |
const showGame = () => setOpponentName(opponentName || DEFAULT_NAME) | |
// Prefer not to use functions to return components | |
let content = null | |
if (loading) { | |
// Page is loading. | |
content = <Spinner/> | |
} else if (opponentName) { | |
// A game is running. | |
content = <Game/> | |
} else { | |
// Prompt user to start a new game. | |
content = <button onClick={showGame}>click</button> | |
} | |
return [<Header/>, content] | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment