Skip to content

Commit 2186a7f

Browse files
committed
Minor changes
1 parent 74d75ce commit 2186a7f

File tree

5 files changed

+37
-13
lines changed

5 files changed

+37
-13
lines changed

Class Notes/my-app/src/components/Cockpit/Cockpit.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import React from 'react';
22
import styled from 'styled-components';
33

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+
413
const StyledButton = styled.button`
514
background-color: ${props => props.alt ? 'red' : 'green'};
615
color: white;
@@ -15,18 +24,9 @@ const StyledButton = styled.button`
1524
}
1625
`;
1726

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-
2727
return(
2828
<div>
29-
<h1>Hi, I'm a React App</h1>
29+
<h1>{props.title}</h1>
3030
<p className={classes.join(' ')}>This is really working!</p>
3131
<StyledButton
3232
alt={props.showPersons}

Class Notes/my-app/src/components/Persons/Person/Person.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const StyledDiv = styled.div`
1616
`;
1717

1818
const person = (props) => {
19+
console.log('[Person.js] rendering...')
1920
// const rnd = Math.random();
2021
// if (rnd > 0.7) {
2122
// throw new Error("Something went wrong");
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import React from 'react';
22
import Person from './Person/Person';
33

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) => {
57
return (
68
<Person
79
click={() => props.clicked(index)}
@@ -10,5 +12,6 @@ const persons = (props) => props.persons.map((person, index) => {
1012
key={person.id}
1113
changed={event => props.changed(event, person.id)}/>);
1214
});
15+
}
1316

1417
export default persons;

Class Notes/my-app/src/containers/App.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ import Cockpit from '../components/Cockpit/Cockpit';
66

77

88
class App extends Component {
9+
10+
constructor(props) {
11+
super(props)
12+
console.log('[App.js] constructor');
13+
}
14+
915
state = {
1016
persons: [
1117
{ id: 'asfa1', name: 'Max', age: 28 },
@@ -16,6 +22,19 @@ class App extends Component {
1622
showPersons: false
1723
};
1824

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+
1938
nameChangedHandler = (event, id) => {
2039
const personIndex = this.state.persons.findIndex(p => {
2140
return p.id === id;
@@ -48,7 +67,7 @@ class App extends Component {
4867
};
4968

5069
render() {
51-
70+
console.log('[App.js] render');
5271
let persons = null;
5372

5473
if (this.state.showPersons) {
@@ -71,6 +90,7 @@ class App extends Component {
7190
return (
7291
<div className="App">
7392
<Cockpit
93+
title={this.props.appTitle}
7494
showPersons={this.state.showPersons}
7595
persons={this.state.persons}
7696
clicked={this.togglePersonsHandler} />

Class Notes/my-app/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import reportWebVitals from './reportWebVitals';
66

77
ReactDOM.render(
88
<React.StrictMode>
9-
<App />
9+
<App appTitle="Person Manager"/>
1010
</React.StrictMode>,
1111
document.getElementById('root')
1212
);

0 commit comments

Comments
 (0)