Created
February 18, 2017 11:31
-
-
Save kenmori/5c61e27a1f59bcabb50ef05f8653b157 to your computer and use it in GitHub Desktop.
Reactl_flowtyped_classSyntax_example.js
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
| /* @flow */ | |
| //https://github.com/facebook/flow/issues/1517 | |
| import React, {Component} from 'react'; | |
| type Props = { | |
| title: string, | |
| visited: boolean, | |
| value: number | |
| } | |
| type State = { | |
| value: number | |
| } | |
| export class FlowTypedCounter extends Component { | |
| state: State; | |
| constructor(props: Props){ | |
| super(props); | |
| this.state = { | |
| value : this.props.value | |
| } | |
| const self: any = this | |
| self._increment = this._increment.bind(this); | |
| self._decrement = this._decrement.bind(this); | |
| }; | |
| _increment (e:any) { | |
| this.setState({ | |
| value: this.state.value + 1 | |
| }) | |
| } | |
| _decrement (e:any) { | |
| this.setState({ | |
| value: this.state.value -1 | |
| }) | |
| } | |
| render(){ | |
| return ( | |
| <div> | |
| <button type='button' onClick={this._increment}>increment</button> | |
| <button type='button' onClick={this._decrement}>decrement</button> | |
| <input type='text' value={this.state.value} /> | |
| </div> | |
| ) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment