Last active
October 25, 2015 01:58
-
-
Save novacrazy/5cd14202a18d09a9ae4e to your computer and use it in GitHub Desktop.
Example
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 * as React from 'react'; | |
class MyWidget extends React.Component { | |
static displayName = 'MyWidget'; | |
static propTypes = { | |
itemUrl: React.PropTypes.string.isRequired, | |
name: React.PropTypes.string.isRequired | |
}; | |
//initial state | |
state = { | |
clicks: 0 | |
}; | |
onClick(event) { | |
event.preventDefault(); | |
const {clicks} = this.state; | |
this.setState({clicks: clicks + 1}); | |
} | |
render() { | |
const {itemUrl, name} = this.props; | |
const {clicks} = this.state; | |
return ( | |
<div> | |
<a href={itemUrl} onClick={this.onClick.bind(this)}>{name}</a> | |
(Clicked {clicks} time{clicks > 1 ? 's' : ''}) | |
</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
import {List} from 'immutable'; | |
import {Phone} from './someFileWithPhoneDeclared.js'; | |
class MyComponent extends React.Component { | |
... //other stuff | |
state = { | |
phones: new List() | |
}; | |
onAddNewPhoneClick(event) { | |
event.preventDefault(); | |
const {phones} = this.state; | |
this.setState({ | |
phones: phones.push(new Phone()) //Immutable.js returns a NEW list with the pushed value | |
}); | |
} | |
... //other stuff | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment