Created
February 13, 2018 02:10
-
-
Save ryu1-1uyr/d4c9f5dd153e77fd05a015a43536f620 to your computer and use it in GitHub Desktop.
reactのサンプルコード setStateとかpropsとかeventの渡しかたとか
This file contains hidden or 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'; | |
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