ReactJS is all about building reusable components. In fact, with React the only thing you do is build components. Since they’re so encapsulated, components make code reuse, testing, and separation of concerns easy. Let see the example below:
<!DOCTYPEhtml><html><head><metacharset="UTF-8"><title></title><scripttype="text/javascript"src="http://fb.me/react-0.12.2.js"></script><scripttype="text/javascript"src="http://fb.me/JSXTransformer-0.12.2.js"></script></head><body><scripttype="text/jsx">varApp=React.createClass({getInitialState:function(){return{red:0}},update:function(e){this.setState({red:this.refs.red.refs.inp.getDOMNode().value});},render:function(){return(<div><NumInputref="red"min={0}max={255}step={0.01}val={this.state.red}type="number"label="Red"update={this.update}/></div>);}});varNumInput=React.createClass({propTypes:{min:React.PropTypes.number,max:React.PropTypes.number,step:React.PropTypes.number,val:React.PropTypes.number,label:React.PropTypes.string,update:React.PropTypes.func.isRequired,type:React.PropTypes.oneOf(['number','range'])},getDefaultProps:function(){return{min:0,max:0,step:1,val:0,label:'',type:'range'}},render:function(){varlabel=this.props.label!==''?<label>{this.props.label}{this.props.val}</label> : ''return(<div><inputref="inp"type={this.props.type}min={this.props.min}max={this.props.max}step={this.props.step}defaultValue={this.props.val}onChange={this.props.update}/>{label}</div>);}});React.render(<Apptxt="this is the txt prop"/>,document.body);</script></body></html>