@@ -8,18 +8,14 @@ import ReactDOM from 'react-dom';
8
8
9
9
const ThemeContext = React . createContext ( { } ) ;
10
10
11
- const Title = ( { children} ) => (
12
- < ThemeContext . Consumer >
13
- { ( { color} ) => < h2 style = { { color} } > { children } </ h2 > }
14
- </ ThemeContext . Consumer >
15
- ) ;
16
- const Button = ( { children} ) => (
17
- < ThemeContext . Consumer >
18
- { ( { color, borderRadius} ) => (
19
- < button style = { { borderRadius, color, borderColor : color } } > { children } </ button >
20
- ) }
21
- </ ThemeContext . Consumer >
22
- ) ;
11
+ const Title = ( { children} ) => {
12
+ const { color} = React . useContext ( ThemeContext ) ;
13
+ return < h2 style = { { color} } > { children } </ h2 > ;
14
+ } ;
15
+ const Button = ( { children} ) => {
16
+ const { color, borderRadius} = React . useContext ( ThemeContext ) ;
17
+ return < button style = { { borderRadius, color, borderColor : color } } > { children } </ button > ;
18
+ } ;
23
19
24
20
const Card = ( ) => {
25
21
const theme = { color : 'purple' , borderRadius : 0 } ;
@@ -39,19 +35,17 @@ const Card = () => {
39
35
) ;
40
36
} ;
41
37
42
- class App extends React . Component {
43
- render ( ) {
44
- const theme = { color : '#3683CE' , borderRadius : '10px' } ;
45
- return (
46
- < div className = "App" >
47
- < ThemeContext . Provider value = { theme } >
48
- < Title > Un titre de page</ Title >
49
- < Button > Un bouton</ Button >
50
- < Card />
51
- </ ThemeContext . Provider >
52
- </ div >
53
- ) ;
54
- }
55
- }
38
+ const App = ( ) => {
39
+ const theme = { color : '#3683CE' , borderRadius : '10px' } ;
40
+ return (
41
+ < div className = "App" >
42
+ < ThemeContext . Provider value = { theme } >
43
+ < Title > Un titre de page</ Title >
44
+ < Button > Un bouton</ Button >
45
+ < Card />
46
+ </ ThemeContext . Provider >
47
+ </ div >
48
+ ) ;
49
+ } ;
56
50
57
51
ReactDOM . render ( < App /> , document . getElementById ( 'root' ) ) ;
0 commit comments