Reader small image

You're reading from  Beginning React

Product typeBook
Published inJul 2018
Reading LevelBeginner
Publisher
ISBN-139781789530520
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Andrea Chiarelli
Andrea Chiarelli
author image
Andrea Chiarelli

Andrea Chiarelli has over 20 years experience as a software engineer and technical writer. In his professional career, he has used various technologies for the projects he has been involved in: from C# to JavaScript, from Angular to React, from ASP.NET to PhoneGap/Cordova. He has contributed to many online and offline magazines and has been the author of a few books published by Wrox Press and Packt. Currently, he is a senior software engineer at the Italian office of Apparound, Inc. and a regular contributor to HTML.it, an Italian online magazine focused on web technologies. You can follow him on Twitter at @andychiare.
Read more about Andrea Chiarelli

Right arrow

Definition of a Component


As defined in the previous chapter, components are the fundamental building blocks of React. Virtually any visual item in a user interface can be a component. From a formal point of view, we would say that a React component is a piece of JavaScript code defining a portion of a user interface.

Consider the following code in a file:

import React from 'react';

class Catalog extends React.Component {
  render() {
    return <div><h2>Catalog</h2></div>;
  }
}

export default Catalog;

This is an ECMAScript 2015 module, defining a basic React component.

It imports the React namespace from the react module and defines the Catalog class by extending the React.Component class. The module exports the Catalog class as a default export.

The interesting part of this definition is the implementation of the render() method.

The render() method defines the visual part of the component. It may execute any JavaScript code, and it should return a markup expression...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Beginning React
Published in: Jul 2018Publisher: ISBN-13: 9781789530520

Author (1)

author image
Andrea Chiarelli

Andrea Chiarelli has over 20 years experience as a software engineer and technical writer. In his professional career, he has used various technologies for the projects he has been involved in: from C# to JavaScript, from Angular to React, from ASP.NET to PhoneGap/Cordova. He has contributed to many online and offline magazines and has been the author of a few books published by Wrox Press and Packt. Currently, he is a senior software engineer at the Italian office of Apparound, Inc. and a regular contributor to HTML.it, an Italian online magazine focused on web technologies. You can follow him on Twitter at @andychiare.
Read more about Andrea Chiarelli