Last active
January 5, 2018 08:27
-
-
Save kazuma1989/161aea315dd899af20c220150db02c13 to your computer and use it in GitHub Desktop.
React を、サンプルを実装しながら理解する ref: https://qiita.com/kazuma1989/items/410a1c20f4128eb30327
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 { FormApp } from './FormApp'; | |
class App extends Component { | |
render() { | |
return ( | |
<FormApp /> | |
); | |
} | |
} | |
export default App; |
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
class App extends Component { | |
render() { | |
return ( | |
<div> | |
<input type="text" /> | |
<button>SEND</button> | |
</div> | |
); | |
} | |
} |
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
yarn global add create-react-app | |
create-react-app qiita | |
cd qiita | |
yarn start |
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
class App extends React.Component { | |
render() { | |
return ( | |
<h1>Hello world</h1> | |
); | |
} | |
} | |
ReactDOM.render( | |
<App />, | |
document.getElementById('root') | |
); |
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 { Component } from '@angular/core'; | |
@Component({ | |
selector: 'app-form-app', | |
template: ` | |
<div> | |
<input type="text" [(ngModel)]="value"> | |
<button (click)="send()">SEND</button> | |
<div>{{message}}</div> | |
</div> | |
` | |
}) | |
export class FormAppComponent { | |
value = ''; | |
message = ''; | |
send() { | |
const value = this.value; | |
this.value = ''; | |
this.message = value; | |
} | |
} |
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'; | |
export class FormApp extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
value: '', | |
message: '' | |
}; | |
this.handleInput = this.handleInput.bind(this); | |
this.send = this.send.bind(this); | |
} | |
handleInput({ target: { value } }) { | |
this.setState({ | |
value | |
}); | |
} | |
send() { | |
const { value } = this.state; | |
this.setState({ | |
value: '', | |
message: value | |
}); | |
} | |
render() { | |
return ( | |
<div> | |
<input type="text" value={this.state.value} onChange={this.handleInput} /> | |
<button onClick={this.send}>SEND</button> | |
<div>{this.state.message}</div> | |
</div> | |
); | |
} | |
} |
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
export class FormApp extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
value: '', | |
message: '' | |
}; | |
this.handleInput = this.handleInput.bind(this); | |
this.send = this.send.bind(this); | |
} | |
// ... | |
render() { | |
return ( | |
<div> | |
<input type="text" value={this.state.value} onChange={this.handleInput} /> | |
<button onClick={this.send}>SEND</button> | |
<div>{this.state.message}</div> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment