Before going any further into JSX, we need to understand some basic rules to build ReactJS components. First, we're going to detail the basic methods that you've already used to create and render components. Then, we'll move to some rules to create them, and finally, we'll talk about children components.
In order to create a component, we need to use the React.createClass
function. ReactJS components are basically classes. This method returns a ReactJS component definition that has a method named render
, which is mandatory to implement. There are many other methods to configure your component and change its behavior that we are going to cover throughout the book.
This is an example of how to use the createClass
and render
method:
var HelloMessage = React.createClass({ render: function() { return ( <h1>Have a good day!</h1> ); } });