@@ -3,7 +3,7 @@ import Example from "./example";
3
3
import Exercise from "./exercise" ;
4
4
5
5
const Page = ( ) => (
6
- < div >
6
+ < React . Fragment >
7
7
< h2 > Context</ h2 >
8
8
< blockquote >
9
9
Accepts a context object (the value returned from React.createContext) and
@@ -12,54 +12,17 @@ const Page = () => (
12
12
<MyContext.Provider> above the calling component in the tree.{ " " }
13
13
< a
14
14
target = "_blank"
15
+ rel = "noopener noreferrer"
15
16
href = "https://reactjs.org/docs/hooks-reference.html#usecontext"
16
17
>
17
18
React docs
18
19
</ a >
19
20
</ blockquote >
20
21
< h3 > Example</ h3 >
21
22
< Example />
22
- < p >
23
- File: < code > src/components/patterns/Context/example/Modal.jsx</ code >
24
- </ p >
25
- < h3 > Exercise</ h3 >
26
- < p >
27
- We are going to create a < strong > Theme Switcher</ strong > component using
28
- Context. If you see{ " " }
29
- < code > src/components/patterns/Context/exercise/theme.js</ code > , there are{ " " }
30
- < strong > 2 themes defined</ strong > . You should be able to toggle between
31
- these 2 themes.
32
- </ p >
33
- < p > This component should:</ p >
34
- < ul >
35
- < li >
36
- Track the current < code > theme</ code > in the state
37
- </ li >
38
- < li > Implement a fucntion to toggle the theme</ li >
39
- < li >
40
- pass the current theme to the < code > ThemeProvider</ code > from{ " " }
41
- < code > styled-components</ code >
42
- </ li >
43
- </ ul >
44
- < p >
45
- In order to check if the theme is actually changing, you can refactor the{ " " }
46
- < code > Hero</ code > component (
47
- < code > src/components/patterns/Context/exercise/components/Hero.jsx</ code > )
48
- </ p >
49
- < p >
50
- Also, in order to toggle the theme, you need to use the{ " " }
51
- < code > ThemeContext.Consumer</ code > in order to get access to the function
52
- that toggles the state in your ThemeProvider.
53
- </ p >
54
- < Exercise />
55
23
< hr />
56
- < h3 > Bonus Exercise</ h3 >
57
- < p >
58
- Implement the Redux Provider in
59
- < code > src/components/patterns/Context/xbonus/Provider.js</ code > . Once
60
- implemented, use it in Root.js
61
- </ p >
62
- </ div >
24
+ < Exercise />
25
+ </ React . Fragment >
63
26
) ;
64
27
65
28
export default Page ;
0 commit comments