ReactJS: A simple react component

This entry is part 36 of 35 in the series React JS

https://codepen.io/darylw/pen/NLxmMX

/*
 * A simple React component
 */
class Application extends React.Component {
  render() {
    return <div>
      <h1>Hello, from codecrawl.com</h1>
      <p>
        More info <a href="https://codecrawl.com" target="_blank">here</a>.
      </p>
    </div>;
  }
}

/*
 * Render the above component into the div#app
 */
React.render(<Application />, document.getElementById('app'));

ReactJS: Input Text Field

This entry is part 4 of 35 in the series React JS

https://codepen.io/gaearon/pen/VmmPgp

class NameForm extends React.Component {
  constructor(props) {
    super(props);
    this.state = {value: ''};

    this.handleChange = this.handleChange.bind(this);
    this.handleSubmit = this.handleSubmit.bind(this);
  }

  handleChange(event) {
    this.setState({value: event.target.value});
  }

  handleSubmit(event) {
    alert('A name was submitted: ' + this.state.value);
    event.preventDefault();
  }

  render() {
    return (
      <form onSubmit={this.handleSubmit}>
        <label>
          Name:
          <input type="text" value={this.state.value} onChange={this.handleChange} />
        </label>
        <input type="submit" value="Submit" />
      </form>
    );
  }
}

ReactDOM.render(
  <NameForm />,
  document.getElementById('root')
);

ReactJS radio button

This entry is part 3 of 35 in the series React JS

http://jsbin.com/mozegodapa/edit?html,js,console,output

class App extends React.Component {

  setFruit(event) {
    console.log(event.target.value);
  }

  render() {
    return (
      <div onChange={this.setFruit.bind(this)}>
        <input type="radio" value="Apple" name="fruit"/> Apple
        <input type="radio" value="Orange" name="fruit"/> Orange
      </div>
     )
  }
}

ReactDOM.render(<App/>, document.getElementById('app'));