React Base Fiddle (JSX)

Starting point for creating JSFiddles with React. This uses React with Addons.

by Mayank Shukla

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.24/browser.js"></script>
<script src="https://npmcdn.com/react@latest/dist/react-with-addons.js"></script>
<script src="https://npmcdn.com/react-dom@latest/dist/react-dom.js"></script>
<script src="https://facebook.github.io/react/js/jsfiddle-integration-babel.js"></script>

<div id="container">
    <!-- This element's contents will be replaced with your component. -->
</div>

JavaScript 1.7

class PasswordForm extends React.Component {
  constructor(props) {
    super(props);
    this.state = {value: ''};
    this.onclick = this.onclick.bind(this);
  }
  
  onclick(){
   if(this.name.value == ''){
        this.name.focus();
        return;
     }else if(this.pass.value == ''){
        this.pass.focus();
        return;
     }
     console.log('api call');
  }
  
  keyDown(e){
       if(e.keyCode == 13){
           this.onclick();
       }
  }

 render() {
 return <div>
     <input ref={(name)=>{this.name=name;}}  name='a' onKeyDown={this.keyDown.bind(this)}/>
     <input ref={(pass)=>{this.pass=pass;}} onKeyDown={this.keyDown.bind(this)}/>
     <input type='button' value='click' onClick={this.onclick}/>
 </div> ;
}
}


ReactDOM.render(
  <PasswordForm/>,
  document.getElementById('container')
);