Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
React.js Essentials

You're reading from  React.js Essentials

Product type Book
Published in Aug 2015
Publisher Packt
ISBN-13 9781783551620
Pages 208 pages
Edition 1st Edition
Languages
Author (1):
Artemij Fedosejev Artemij Fedosejev
Profile icon Artemij Fedosejev

Table of Contents (18) Chapters

React.js Essentials
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Installing Powerful Tools for Your Project 2. Create Your First React Element 3. Create Your First React Component 4. Make Your React Components Reactive 5. Use Your React Components with Another Library 6. Update Your React Components 7. Build Complex React Components 8. Test Your React Application with Jest 9. Supercharge Your React Architecture with Flux 10. Prepare Your React Application for Painless Maintenance with Flux Index

Creating the Button component


Create the following ~/snapterest/source/components/Button.react.js file:

var React = require('react');

var buttonStyle = {
  margin: '10px 10px 10px 0'
};

var Button = React.createClass({
  render: function () {
    return (
      <button
        className="btn btn-default"
        style={buttonStyle}
        onClick={this.props.handleClick}>{this.props.label}</button>
    );
  }
});

module.exports = Button;

The Button component renders a button. You might be wondering what's the benefit of creating a dedicated component for a button if you could just use the <button> element? Think of a component as a wrapper for a <button> element and something else that comes with it. In our case, most <button> elements come with the same style, so it makes sense to encapsulate both the <button> and style objects inside a component, and reuse that component. Hence, the Button component. It expects to receive two properties from a parent component:

  • The label property is a label for a button

  • The handleClick property is a callback function that is called when a user clicks on this button

Now, it's time to create our CollectionExportForm component.

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 $15.99/month. Cancel anytime}