Book Image

React.js Essentials

By : Artemij Fedosejev
Book Image

React.js Essentials

By: Artemij Fedosejev

Overview of this book

Table of Contents (18 chapters)
React.js Essentials
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating your first stateless React component


Let's take a look at the following example of how to create a React component:

var React = require('react');
var ReactDOM = require('react-dom');

var ReactClass = React.createClass({
  render: function () {
    return React.createElement('h1', { className: 'header' }, 'React Component');
  }
});
var reactComponentElement = React.createElement(ReactClass);
var reactComponent = ReactDOM.render(reactComponentElement, document.getElementById('react-application'));

Some of the preceding code should already look familiar to you, and the rest can be broken down into three simple steps:

  1. Creating a React class.

  2. Creating a React component element.

  3. Creating a React component.

Let's take a closer look at how we can create a React component:

  1. Create a ReactClass by calling the React.createClass() function and providing a specification object as its parameter. In this chapter, we'll focus on learning about the specification objects in more detail.

  2. Create a ReactComponentElement...