Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejs
titleReactJS State
var Notice = React.createClass({
    getInitialState: function() {
		return {status: false, message: ""};
	},
	render: function() {
		if (this.state.status) {
			return <span class="Alert">{this.state.message}</span>;
		} else {
			return <span class="Normal">All is well</span>;
		}
	}
});

Whenever the Notice's state.status changes, ReactJS runs the Notice.render function which returns a <span> with a an alert message or "All is well". 

...