How to React

... js

Kent C. Dodds


wife, 4 kids, & a dog

PayPal, Inc.

Please Stand...

if you are able ❤️ ♿️

What this talk is

  • About abstraction and React
  • Fundamental principles


What is abstraction?

Let's take a look at an example...

// $(el).toggleClass(className);

function toggleClass(el, className) {
  if (el.classList) {
  } else {
    var classes = el.className.split(' ');
    var existingIndex = -1;
    for (var i = classes.length; i--;) {
      if (classes[i] === className)
        existingIndex = i;

    if (existingIndex >= 0) {
      classes.splice(existingIndex, 1);
    } else {

    el.className = classes.join(' ');

2 questions

Before using an abstraction

  1. What is the benefit of this abstraction?
  2. What is the cost of this abstraction?

What if we use it before we know the answers?

// $(el).toggleClass(className)

function toggleClass(el, className) {

What costs are there?



time investment

abstraction abandonment

Side note...

Want to just play around with stuff?

Want to just ship stuff?

That's totally cool.

Just recognize you don't know the all trade-offs...

So how do we start with React?

Start with JavaScript

And Modern JavaScript

Next, let's learn React



Dependencies and npm

Using npm...

Single Page App?

Let's learn routing with react-router!

State Management

Lifting State Up

- React Docs

this.setState -> this.props.onChange

this.state.value -> this.props.value

Unchanged state?

JavaScript module (singleton)

Simple state?

React's Official Context API!

Complex state?

VERY complex state?

Component Styling?

Let's do some CSS-in-JS!

Why CSS-in-JS?

  • Scoped styles
  • Critical CSS
  • Smarter optimisations
  • Package management
  • Non-browser styling
  • Colocation of concerns

From here...

Learn these in any order

  1. Relay/Apollo (GraphQL)
  2. Server Rendering
  3. Immutable.js

Thank you!