File tree Expand file tree Collapse file tree 5 files changed +37
-13
lines changed Expand file tree Collapse file tree 5 files changed +37
-13
lines changed Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
import styled from 'styled-components' ;
3
3
4
+ const cockpit = ( props ) => {
5
+ const classes = [ ] ;
6
+ if ( props . persons . length <= 2 ) {
7
+ classes . push ( 'red' ) ; // classes = ['red']
8
+ }
9
+ if ( props . persons . length <= 1 ) {
10
+ classes . push ( 'bold' ) ; // classes = ['red', 'bold']
11
+ }
12
+
4
13
const StyledButton = styled . button `
5
14
background-color: ${ props => props . alt ? 'red' : 'green' } ;
6
15
color: white;
@@ -15,18 +24,9 @@ const StyledButton = styled.button`
15
24
}
16
25
` ;
17
26
18
- const cockpit = ( props ) => {
19
- const classes = [ ] ;
20
- if ( props . persons . length <= 2 ) {
21
- classes . push ( 'red' ) ; // classes = ['red']
22
- }
23
- if ( props . persons . length <= 1 ) {
24
- classes . push ( 'bold' ) ; // classes = ['red', 'bold']
25
- }
26
-
27
27
return (
28
28
< div >
29
- < h1 > Hi, I'm a React App </ h1 >
29
+ < h1 > { props . title } </ h1 >
30
30
< p className = { classes . join ( ' ' ) } > This is really working!</ p >
31
31
< StyledButton
32
32
alt = { props . showPersons }
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ const StyledDiv = styled.div`
16
16
` ;
17
17
18
18
const person = ( props ) => {
19
+ console . log ( '[Person.js] rendering...' )
19
20
// const rnd = Math.random();
20
21
// if (rnd > 0.7) {
21
22
// throw new Error("Something went wrong");
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
import Person from './Person/Person' ;
3
3
4
- const persons = ( props ) => props . persons . map ( ( person , index ) => {
4
+ const persons = ( props ) => {
5
+ console . log ( '[Persons.js] rendering...' )
6
+ return props . persons . map ( ( person , index ) => {
5
7
return (
6
8
< Person
7
9
click = { ( ) => props . clicked ( index ) }
@@ -10,5 +12,6 @@ const persons = (props) => props.persons.map((person, index) => {
10
12
key = { person . id }
11
13
changed = { event => props . changed ( event , person . id ) } /> ) ;
12
14
} ) ;
15
+ }
13
16
14
17
export default persons ;
Original file line number Diff line number Diff line change @@ -6,6 +6,12 @@ import Cockpit from '../components/Cockpit/Cockpit';
6
6
7
7
8
8
class App extends Component {
9
+
10
+ constructor ( props ) {
11
+ super ( props )
12
+ console . log ( '[App.js] constructor' ) ;
13
+ }
14
+
9
15
state = {
10
16
persons : [
11
17
{ id : 'asfa1' , name : 'Max' , age : 28 } ,
@@ -16,6 +22,19 @@ class App extends Component {
16
22
showPersons : false
17
23
} ;
18
24
25
+ static getDerivedStateFromProps ( props , state ) {
26
+ console . log ( '[App.js] getDeprivedStateFromProps' , props ) ;
27
+ return state ;
28
+ }
29
+
30
+ componentWillMount ( ) {
31
+ console . log ( '[App.js] componentWillMount' )
32
+ }
33
+
34
+ componentDidMount ( ) {
35
+ console . log ( '[App.js] componentDidMount' )
36
+ }
37
+
19
38
nameChangedHandler = ( event , id ) => {
20
39
const personIndex = this . state . persons . findIndex ( p => {
21
40
return p . id === id ;
@@ -48,7 +67,7 @@ class App extends Component {
48
67
} ;
49
68
50
69
render ( ) {
51
-
70
+ console . log ( '[App.js] render' ) ;
52
71
let persons = null ;
53
72
54
73
if ( this . state . showPersons ) {
@@ -71,6 +90,7 @@ class App extends Component {
71
90
return (
72
91
< div className = "App" >
73
92
< Cockpit
93
+ title = { this . props . appTitle }
74
94
showPersons = { this . state . showPersons }
75
95
persons = { this . state . persons }
76
96
clicked = { this . togglePersonsHandler } />
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ import reportWebVitals from './reportWebVitals';
6
6
7
7
ReactDOM . render (
8
8
< React . StrictMode >
9
- < App />
9
+ < App appTitle = "Person Manager" />
10
10
</ React . StrictMode > ,
11
11
document . getElementById ( 'root' )
12
12
) ;
You can’t perform that action at this time.
0 commit comments