Last active
June 4, 2019 08:40
-
-
Save aramis-it/1dceb9eabffba5a65757bec4f7b6b60c to your computer and use it in GitHub Desktop.
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, ChangeEvent } from 'react'; | |
| // props -н төрлийг зааж өгж байна | |
| type propsTypes = { | |
| name: string | |
| } | |
| // state -н төрлийг зааж өгч байна | |
| type stateTypes = { | |
| name: string | |
| } | |
| export default class App extends Component<propsTypes, stateTypes> { | |
| // байгуулагч функцийг зарлах шаардлагагүй | |
| state: stateTypes = { | |
| name: this.props.name | |
| } | |
| onChange = (e: ChangeEvent<HTMLInputElement>) => { | |
| this.setState({ name: e.target.value }) | |
| } | |
| public render() { | |
| return ( | |
| <div> | |
| <input type="text" name="name" value={this.state.name} onChange={e => this.onChange(e)} /> | |
| <br /> | |
| <h1>Name: {this.state.name}</h1> | |
| </div> | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment