@@ -8,6 +8,9 @@ import Cockpit from '../Components/Cockpit/Cockpit'
8
8
import WithClass from '../hoc/WithClass' ;
9
9
// import ErrorBoundary from './ErrorBoundary/ErrorBoundary';
10
10
11
+ export const AuthContext = React . createContext ( false ) ;
12
+
13
+
11
14
class App extends PureComponent {
12
15
constructor ( props ) {
13
16
super ( props ) ;
@@ -34,8 +37,17 @@ class App extends PureComponent {
34
37
// }
35
38
36
39
componentWillUpdate ( nextProps , nextState ) {
37
- console . log ( 'Inside componentWillUpdate, nextProps' ) ;
40
+ console . log ( 'Inside componentWillUpdate' , nextProps , nextState ) ;
41
+
42
+ }
43
+
44
+ static getDerivedStateFromProps ( nextProps , prevState ) {
45
+ console . log ( '[UPDATE App.js] Inside getDerivedStateFromProps ' , nextProps , prevState ) ;
46
+ return prevState ;
47
+ }
38
48
49
+ getSnapshotBeforeUpdate ( ) {
50
+ console . log ( '[UPDATE App.js] Inside getSnapshotBeforeUpdate' ) ;
39
51
}
40
52
41
53
componentDidUpdate ( ) {
@@ -50,7 +62,8 @@ class App extends PureComponent {
50
62
] ,
51
63
otherState : 'joku muu value' ,
52
64
showPersons : false ,
53
- timesClicked : 0
65
+ timesClicked : 0 ,
66
+ authenticated : false
54
67
}
55
68
56
69
nimiChangedHandler = ( event , id ) => {
@@ -72,6 +85,11 @@ class App extends PureComponent {
72
85
console . log ( 'id:' , id ) ;
73
86
}
74
87
88
+ loginHandler = ( ) => {
89
+ this . setState ( { authenticated : true } )
90
+
91
+ }
92
+
75
93
togglePersonsHandler = ( ) => {
76
94
let personsLength = this . state . persons . length
77
95
console . log ( 'personsLength' , personsLength ) ;
@@ -103,9 +121,11 @@ class App extends PureComponent {
103
121
104
122
persons = (
105
123
< div >
106
- < Persons persons = { this . state . persons }
124
+ < Persons
125
+ persons = { this . state . persons }
107
126
clicked = { this . deletePersonHandler }
108
127
changed = { this . nimiChangedHandler }
128
+
109
129
/>
110
130
</ div >
111
131
) ;
@@ -122,8 +142,12 @@ class App extends PureComponent {
122
142
showPersons = { this . state . showPersons }
123
143
persons = { this . state . persons }
124
144
clicked = { this . togglePersonsHandler }
145
+ login = { this . loginHandler }
125
146
/>
147
+ < AuthContext . Provider
148
+ value = { this . state . authenticated } >
126
149
{ persons }
150
+ </ AuthContext . Provider >
127
151
</ div >
128
152
) ;
129
153
0 commit comments