Skip to content

Commit fafe601

Browse files
committed
Context Setup
1 parent a2f693d commit fafe601

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

src/App.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1-
import React from 'react'
2-
import { useGlobalContext } from './context'
1+
import React from "react";
2+
import { useGlobalContext } from "./context";
33

4-
import SetupForm from './SetupForm'
5-
import Loading from './Loading'
6-
import Modal from './Modal'
4+
import SetupForm from "./SetupForm";
5+
import Loading from "./Loading";
6+
import Modal from "./Modal";
77
function App() {
8-
return <h2>quiz starter</h2>
8+
const { waiting, loading, questions, index, correct } = useGlobalContext();
9+
10+
if (waiting) {
11+
return <SetupForm></SetupForm>;
12+
}
13+
14+
if (loading) {
15+
return <Loading></Loading>;
16+
}
17+
18+
return <main>quiz app</main>;
919
}
1020

11-
export default App
21+
export default App;

src/context.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,29 @@ const tempUrl =
1717
const AppContext = React.createContext();
1818

1919
const AppProvider = ({ children }) => {
20-
return <AppContext.Provider value="hello">{children}</AppContext.Provider>;
20+
const [waiting, setWaiting] = useState(true);
21+
const [loading, setLoading] = useState(false);
22+
const [questions, setQuestions] = useState([]);
23+
const [index, setIndex] = useState(0);
24+
const [correct, setCorrect] = useState(0);
25+
const [error, setError] = useState(false);
26+
const [isModalOpen, setIsModalOpen] = useState(false);
27+
28+
return (
29+
<AppContext.Provider
30+
value={{
31+
waiting,
32+
loading,
33+
questions,
34+
index,
35+
correct,
36+
error,
37+
isModalOpen,
38+
}}
39+
>
40+
{children}
41+
</AppContext.Provider>
42+
);
2143
};
2244
// make sure use
2345
export const useGlobalContext = () => {

0 commit comments

Comments
 (0)