import BackboneMixin from 'mixins/backbone';
const ComponentName = React.createClass({
// Declare the prop types.
// The are optional unless marked `isRequired`
propTypes: {
list: React.PropTypes.array, // i.e. this.props.list must be an array
isReady: React.PropTypes.bool,
onDecrement: React.PropTypes.func, // callbacks are usually prefixed with 'on'
remaining: React.PropTypes.number,
data: React.PropTypes.object,
description: React.PropTypes.string.isRequired
},
mixins: [BackboneMixin],
// return an object representing default props
// (much like Backbone.Model defaults)
getDefaultProps() {
return {isReady: false};
},
// called when a component is initialized
// return an object representing the initial state
getInitialState() {
return {
isSelected: false,
remaining: this.props.initialCount
};
},
componentWillMount() {}, // called when a component is attached to the DOM
componentDidMount() {}, // called after a component is attached to the DOM
// called when props are updated, but not on init
// often used to set state for props
componentWillReceiveProps(/*object*/ nextProps) {
this.setState({
remaining: nextProps.initialCount
});
},
componentWillUpdate(/*object*/ nextProps, /*object*/ nextState) {}, // called before the component is re-rendered, returning false cancels
componentDidUpdate(/*object*/ prevProps, /*object*/ prevState) {}, // called when the component did update
componentWillUnmount() {}, // called when a component is removed from the DOM
// custom methods added to this component...
// event handlers are usually prefixed with 'handle'
handleClick() {
let remaining = this.state.remaining - 1;
this.setState({
remaining: remaining
});
this.props.onDecrement(remaining);
},
// called by React whenever the state changes
render() {
return
}
});