Skip to content

Instantly share code, notes, and snippets.

@ryu1-1uyr
Created February 13, 2018 02:10
Show Gist options
  • Save ryu1-1uyr/d4c9f5dd153e77fd05a015a43536f620 to your computer and use it in GitHub Desktop.
Save ryu1-1uyr/d4c9f5dd153e77fd05a015a43536f620 to your computer and use it in GitHub Desktop.
reactのサンプルコード setStateとかpropsとかeventの渡しかたとか 
import React, { Component } from 'react';
class App extends Component {
constructor(props){
super(props);
this.state = {text:'hello'};
}
changeText(event){
console.log(event.target.value);
this.setState({text:event.target.value});
}
render() {
return (
<div>
<TextView value = {this.state.text}/>
<input type="text" onChange={(event)=>{this.changeText(event)}}/>
</div>
);
}
}
const TextView = (props) => {
return (
<div>{props.value}</div>
);
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment