Hacking with React

Retired

This book is no longer available for sale.

Hacking with React

Get started with React, React Router, Jest, Webpack, ES6 and more with this hands-on guide.

About the Book

It's impossible to work on the web without having heard about React. Facebook developed it, but Airbnb are using it, as are Netflix, Uber and many more. And with good reason: React is a whole new way of developing complex web applications in a way that allows you to spend more time writing great code and less time fighting with the DOM.

I wrote Hacking with React with one goal in mind: to teach React coding in the fastest, most efficient way possible. After setting up your computer so that it's ready for development, you start coding with React immediately – there's no boring "History of web" chapter that rants on about how the internet was created. Instead, it's all code, all the time.

"What code is it?" I hear you ask. Well, let me tell you: it's React 0.14, the incredible new user interface toolkit. It's React Router, the smartest way to load and unload components as users change URL. It's JSX, the incredible new JavaScript syntax extension that lets you write inline XML. It's ES6, Webpack and Babel so you get to use powerful new features like string interpolation and classes along with hot reloading for faster development. It's Jest and ESLint, so you can write tests that prove your code works and has consistent syntax.

In short, it uses the very latest technology the web has to offer so that you learn quickly and easily.

Here are just some of the topics covered:

  • How to install Webpack, Babel and React for development with ES6.
  • How to create a React component and import it into an application.
  • How to write JSX to render content.
  • How to use props to give a component values.
  • How to handle events such as onClick.
  • How to use React state, and how it differs from props.
  • How to fetch data from GitHub using SuperAgent and Ajax.
  • How to use string interpolation and computed property names.
  • How to create routes using React Router.
  • How to create links between pages using <Link>.
  • How to render default content using <IndexRoute>.
  • How to use Jest to test React component rendering.
  • How to use Jest to simulate user interface with controls.
  • How to create asynchronous tests using waitFor() and runs().
  • How to lint your React code using ESLint and Babel.

In short, this book is the fastest way to get up to speed with React development, and is guaranteed to jump start your learning. Even better, your purchase includes any future updates free of charge!

You can download the complete source code for the book from GitHub at https://github.com/twostraws/HackingWithReact.

About the Author

Paul Hudson
Paul Hudson

Paul Hudson is an award-winning developer and technical writer, having published Hacking with Swift, Hacking with PHP, PHP in a Nutshell, Ubuntu Unleashed, and been editor of Linux Format magazine. His apps are used by the likes of MacLife magazine, Edge magazine, Fender, Virgin, Jamie Oliver, Odeon, Tesco, and more.

Table of Contents

  • Welcome!
  • Begin at the Beginning: Chapter One
  • The Importance of using Webpack with React
  • Introduction to JSX
  • Importing React Components using ES6
  • What are React Props?
  • Generating Random Values for Our Page
  • How to Write if/else Conditional Statements in JSX
  • Using JSX to Render Several Elements at Once
  • Handling Events with JSX: onClick
  • State vs Props in React
  • Changing a React Component’s State with setState()
  • State and the Single Source of Truth
  • Rendering an Array of Data with map() and JSX
  • Cleaning up and Preparing for a Real Project
  • Fetching Ajax Data from GitHub using SuperAgent
  • Converting GitHub’s JSON into Meaningful JSX
  • Time for a Task: Reading from Three Feeds
  • How to Upgrade Our App to Read Three Feeds
  • Refactoring our Ajax Code: Don’t Repeat Yourself
  • Refactoring our State Code: Passing Parameters in onClick
  • Introducing React Router
  • How to Add a New Route to React Router
  • Creating a Link Between Pages in React Router
  • Making Custom URLs with React Router Params
  • Adding a Root Route Using React Router and IndexRoute
  • Cleaning up Our Routes and Preparing for the Next Step
  • Time for a Test: Clickable Usernames
  • Making Usernames Clickable: My Solution
  • Time for some Basic User Interface Polish
  • Adding React Router Breadcrumbs with Link and IndexLink
  • The First 80% is Done: Now What?
  • How to Configure Jest to Test React and ES6
  • Creating our First React Test with Jest
  • Using Jest to Test Our React Components
  • Using Jest to Simulate User Interaction on a React Component
  • Time for Ajax: Using Jest with Asynchronous Tests
  • Mocking Ajax with Jest: Making an Asynchronous Test Become Synchronous
  • Cleaning up Our Tests: Last Tweaks
  • Linting React using ESLint and Babel
  • Linting React using Airbnb’s ESLint Rules
  • How to Add React Component Prop Validation in Minutes
  • Bringing it all Together: Project Complete!

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

80% Royalties. Earn $16 on a $20 book.

We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earnedover $13 millionwriting, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub