Skip to content

Instantly share code, notes, and snippets.

@alesanabriav
Last active March 27, 2017 23:19
Show Gist options
  • Save alesanabriav/06e132c40d7650996b6d15c6ba6eea22 to your computer and use it in GitHub Desktop.
Save alesanabriav/06e132c40d7650996b6d15c6ba6eea22 to your computer and use it in GitHub Desktop.
const Component = React.createClass({
getInitialState() {
return {
name: 'ale',
posts: []
}
},
componentWillUpdate() {
console.log(this.state);
},
handleClick(e) {
this.setState({name: 'Julian'});
},
handleName(e) {
let val = e.target.value;
this.setState({name: val});
},
componentWillMount() {
this.setState({name: 'will'});
},
componentDidMount() {
this.setState({name: 'mount'});
},
render() {
return (
<div>
<h1>{this.state.name} {this.props.lastname}</h1>
<p>lorem</p>
<input onChange={this.handleName} value={this.state.name} />
<button onClick={this.handleClick}>event</button>
</div>
)
}
});
const ComponentChild = React.createClass({
getInitialState() {
return {
lastname: ''
}
},
handleLastname(e) {
let val = e.target.value;
this.setState({lastname: val});
},
render() {
return (
<div>
<h3>Give me your Name</h3>
<input onChange={this.handleLastname} />
<Component lastname={this.state.lastname} />
</div>
)
}
});
ReactDOM.render(<ComponentChild postId={1} lastname="san" />, document.querySelector('.nea'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment