Created
April 3, 2020 16:16
-
-
Save RichardBray/724ef01081e5df48cdd017d2e929f394 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
// App.jsx | |
import React, { Fragment } from "react"; | |
// Context | |
import { Store, useAppContext } from "./AppContext"; | |
// - Data | |
import data from "./data.json"; | |
export default function App() { | |
const [chosenAnswers, setChosenAnswers] = useState([]); | |
function renderQuestions() { | |
return data.results.map((result, index) => ( | |
<Question key={index} {...{result, index}} /> | |
)); | |
} | |
return ( | |
<Store.Provider value={{ chosenAnswers, setChosenAnswers }}> | |
<Start /> | |
{renderQuestions()} | |
<Finish /> | |
</Store.Provider> | |
); | |
} | |
function Start() { | |
return ( | |
<Fragment> | |
<h1>Video games</h1> | |
<h2>How much you know about them?</h2> | |
<Button text="Let's go!" func={() => scrollToElem("question-0")} /> | |
</Fragment> | |
); | |
} | |
function Finish() { | |
return ( | |
<Fragment> | |
<h3>Well done!</h3> | |
<h4> | |
You scored {calculateResult(correctAnswers, chosenAnswers)} out of {totalQuestions} | |
</h4> | |
<Button text="start over" func={() => window.location.reload()} /> | |
</Fragment> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment