React Hello World Example with ES6+JSX

A basic Hello World widget with in browser JSX transformed + ES6 support

by kenji morita

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>

CSS

.widget {
    width: 202px;
    margin:100px auto;
//    border:1px solid black;
    padding:20px;
}
.name {
    color: red;
}
.default-label {
    border: 1px solid black;
    padding: 10px;
    margin-bottom: 10px;
    width:180px;
}

.green-label {
    border: 1px solid green;
    padding: 10px;
    margin-bottom: 10px;
    width: 180px;
}

.default-input {
    border: 1px solid #eaeaea;
    padding: 10px;
    width:180px;
}

.important-input {
    border: 2px solid red;
    width:180px;
}

img.center {
    width: 100px;
    height: 100px;
    display: block;
    margin: 15px auto;    
}

JavaScript 1.7

class ParentComponent extends React.Component {
 constructor(props){
  super(this.props)
  this.state = {
   name: "わたし"
  };
  this.onChangeName = this.onChangeName.bind(this);
 }
 onChangeName(){
  const name = this.state.name === "あなた" ? "わたし" : "あなた";
  this.setState({
   name : name
  });
 }
 render(){
  return (
  	<div>
    	<h1>親です</h1>
      <ChildComponent name={this.state.name}></ChildComponent>
   	  <a onClick={this.onChangeName}>click</a>
    </div>
  );
 }
}
class ChildComponent extends React.Component {
 constructor(props){
  super(this.props)
  }
  render(){
    return (
      <div>
			 <h2>題名</h2>
			 <p>{this.props.name}の未来</p>
			</div>
    );
  }
}

      React.render(<ParentComponent />, document.getElementById('container'));