Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Getting Started with React

You're reading from  Getting Started with React

Product type Book
Published in Apr 2016
Publisher
ISBN-13 9781783550579
Pages 212 pages
Edition 1st Edition
Languages
Authors (3):
Doel Sengupta Doel Sengupta
Profile icon Doel Sengupta
Manu Singhal Manu Singhal
Profile icon Manu Singhal
Danillo Corvalan Danillo Corvalan
Profile icon Danillo Corvalan
View More author details

Table of Contents (18) Chapters

Learning JSX and Gotchas


Now it's time to master JSX and learn some Gotchas. You're going to learn some basic concepts to build ReactJS UI components using JSX. It includes practices when writing expressions, conditions, and creating lists of components. It will also walk you through how JSX differs from HTML (because it's not HTML) in some aspects.

Expressions

Consider the following code:

var Clock = React.createClass({
  render: function () {
    var today = new Date();
    return <h1>The time is { today.toLocaleTimeString() }</h1>;
  }
});

React.render(<Clock />, document.body);

JSX understands the curly braces {} whenever you want to put JavaScript code within your presentation code.

In the next example, let's improve our Clock component by supporting greetings depending on what the time is.

In the highlighted code mentioned later, if the current hour is lesser than 4, it should return day, and if the hour is greater than 4 but less than 18, it should return night:

var GreetingsClock...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}