Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="https://fb.me/react-with-addons-0.14.7.min.js"></script>
<script src="https://fb.me/react-dom-0.14.7.min.js"></script>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
<div id="container">
</div>
</body>
</html>
 
var MyComponent = React.createClass({
  getInitialState: function() {
    return {a: "a"};
  },
  handleClick1: function() {
    this.refs.myTextInput1.value="b";
    this.refs.myTextInput2.value="b";
    console.log(this.state.a)
  },
  handleClick2: function() {
    this.setState({a:"b"});
  },
  change1: function(e) {
    alert(e.target.value)
  },
  change2: function(e) {
    alert(e.target.value)
  },
  render: function() {
    return (
      <div>
        <input type="text" ref="myTextInput1" defaultValue={this.state.a} onChange={this.change1}/> 
      <br/>
      <input type="text" ref="myTextInput1" defaultValue="X" /> 
      <br/>
        <input type="text" ref="myTextInput2" value={this.state.a} onChange={this.change2}/> 
      <br/>
        <input type="button" value="changeA" onClick={this.handleClick1} /> 
      <br/>
        <input type="button" value="changeState" onClick={this.handleClick2} /> 
      </div>
    );
  }
});
ReactDOM.render(
  <MyComponent />, 
  document.getElementById('container')
); 
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers