Last active
December 23, 2017 19:00
-
-
Save shahryarjb/5e55b5d4e07710cc143356a98031bd80 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import './App.css'; | |
import Person from './Person/Person'; | |
class App extends Component { | |
constructor(props) { | |
super(props); | |
this.nTestChange = this.nTestChange.bind(this); | |
this.togglePersonsHandler = this.togglePersonsHandler.bind(this); | |
} | |
state = { | |
persons: [ | |
{ name: 'Max', age: 28 }, | |
{ name: 'Manu', age: 29 }, | |
{ name: 'Stephanie', age: 26 } | |
], | |
otherState: 'some other value', | |
showPersons: false | |
} | |
kkk = { | |
State: 'false', | |
show: false | |
} | |
switchNameHandler = (newName) => { | |
// console.log('Was clicked!'); | |
// DON'T DO THIS: this.state.persons[0].name = 'Maximilian'; | |
this.setState( { | |
persons: [ | |
{ name: newName, age: 28 }, | |
{ name: 'Manu', age: 29 }, | |
{ name: 'Stephanie', age: 27 } | |
] | |
} ) | |
} | |
nameChangedHandler = (event) => { | |
this.setState( { | |
persons: [ | |
{ name: 'Max', age: 28 }, | |
{ name: event.target.value, age: 29 }, | |
{ name: 'Stephanie', age: 26 } | |
] | |
} ) | |
} | |
togglePersonsHandler = () => { | |
const doesShow = this.state.showPersons; | |
this.setState({ | |
showPersons: !doesShow | |
}); | |
} | |
nTestChange = () => { | |
const doesShow = this.kkk.show; | |
this.kkk.show = !this.kkk.show; | |
console.log(this.kkk.show); | |
} | |
render () { | |
const style = { | |
backgroundColor: 'white', | |
font: 'inherit', | |
border: '1px solid blue', | |
padding: '8px', | |
cursor: 'pointer' | |
}; | |
return ( | |
<div className="App"> | |
<h1>Hi, I'm a React App</h1> | |
<p>This is really working!</p> | |
<button | |
style={style} | |
onClick={this.togglePersonsHandler}>Toggle Person</button> | |
{ | |
this.state.showPersons ? | |
<div> | |
<Person | |
name={this.state.persons[0].name} | |
age={this.state.persons[0].age} /> | |
<Person | |
name={this.state.persons[1].name} | |
age={this.state.persons[1].age} | |
click={this.switchNameHandler.bind(this, 'Max!')} | |
changed={this.nameChangedHandler} >My Hobbies: Racing</Person> | |
<Person | |
name={this.state.persons[2].name} | |
age={this.state.persons[2].age} /> | |
</div> :null | |
} | |
<button style={style} onClick={this.nTestChange}>Test fight</button> | |
{ this.kkk.show ? | |
<div> | |
<p>Test</p> | |
</div> :null | |
} | |
</div> | |
); | |
// return React.createElement('div', {className: 'App'}, React.createElement('h1', null, 'Does this work now?')); | |
} | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment