React Base Fiddle (JSX)

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

by vivek07mishra

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.1/JSXTransformer.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.1/react-with-addons.js"></script>
<script src="https://facebook.github.io/react/js/jsfiddle-integration.js"></script>

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

<div id="container1">
		
</div>

JavaScript 1.7

var CustomEvents = (function() {
  var _map = {};
 
  return {
    subscribe: function(name, cb) {
      _map[name] || (_map[name] = []);
      _map[name].push(cb);
    },
 
    notify: function(name, data) {
      if (!_map[name]) {
        return;
      }
 
      // if you want canceling or anything else, add it in to this cb loop
      _map[name].forEach(function(cb) {
        cb(data);
      });
    }
  }
})();

var HelloWorld = React.createClass({
    componentDidMount: function(){
    var self = this;
        CustomEvents.subscribe('foo', function(event) {
           
            if(event === 'focus')
             React.findDOMNode(self.refs.mytestinput).focus();
            alert('hi');
        });
    },
  render: function() {
    return (
      <p>
        Hello, <input type="text" ref="mytestinput" placeholder="Your name here" />!<br />
        It is {this.props.date.toTimeString()}
      </p>
    );
  }
});

  React.render(
    <HelloWorld date={new Date()} />,
    document.getElementById('container')
  );

var MyComponent = React.createClass({
  handleClick: function() {
    // Explicitly focus the text input using the raw DOM API.
      CustomEvents.notify('foo','focus');
  },
  render: function() {
    // The ref attribute adds a reference to the component to
    // this.refs when the component is mounted.
    return (
      <div>
        <input type="text" ref="myTextInput" />
        <input
          type="button"
          value="Focus the text input"
          onClick={this.handleClick}
        />
      </div>
    );
  }
});

React.render(
  <MyComponent />,
  document.getElementById('container1')
);