Tutorial

Now that you've read the overview, it's adventure time!

Adventure Time!

In this tutorial, we're going to build a Chess game with React and React DnD. Just kidding! Writing a full-blown Chess game is totally out of scope of this tutorial. What we're going to build is a tiny app with a Chess board and a lonely Knight. The Knight will be draggable according to the Chess rules.

If you're comfortable with React already, feel free to skip ahead to the final section: Adding Drag-and-Drop Interaction

We will use this example to demonstrate the data-driven philosophy of react-dnd. You will learn how to create a drag source and a drop target, wire them together with your React components, and change their appearance in response to the drag and drop events.

Now let's build something!

Table of Contents

Setup

In this tutorial, the code examples are use function-components and modern JavaScript syntax. It's recommended to use a build-step to transpile these features into your target environment. We recommend using create-react-app.

The app we're going to build is available as an example on this website.

Building the Game

Identifying the Components

We're going to start by creating some React components first, with no thoughts of the drag and drop interaction. Which components is our Lonely Knight app going to be made of? I can think of a few:

  • Knight, our lonely knight piece;
  • Square, a single square on the board;
  • Board, the whole board with 64 squares.

Let's consider their props.

  • Knight probably needs no props. It has a position, but there's no reason for the Knight to know it, because it can be positioned by being placed into a Square as a child.

  • It is tempting to give Square its position via props, but this, again, is not necessary, because the only information it really needs for the rendering is the color. I'm going to make Square white by default, and add a black boolean prop. And of course Square may accept a single child: the chess piece that is currently on it. I chose white as the default background color to match the browser defaults.

  • The Board is tricky. It makes no sense to pass Squares as children to it, because what else could a board contain? Therefore it probably owns the Squares. But then, it also needs to own the Knight because this guy needs to be placed inside one of those Squares. This means that the Board needs to know the knight's current position. In a real Chess game, the Board would accept a data structure describing all the pieces, their colors and positions, but for us, a knightPosition prop will suffice. We will use two-item arrays as coordinates, with [0, 0] referring to the A8 square. Why A8 instead of A1? To match the browser coordinate orientation. I tried it another way and it just messed with my head too much.

Where will the current state live? I really don't want to put it into the Board component. It's a good idea to have as little state in your components as possible, and because the Board will already have some layout logic, I don't want to also burden it with managing the state.

The good news is, it doesn't matter at this point. We're just going to write the components as if the state existed somewhere, and make sure that they render correctly when they receive it via props, and think about managing the state afterwards!

Creating the Components

I prefer to start bottom-up, because this way I'm always working with something that already exists. If I were to build the Board first, I wouldn't see my results until I'm done with the Square. On the other hand, I can build and see the Square right away without even thinking of the Board. I think that the immediate feedback loop is important (you can tell that by another project I work on).

In fact I'm going to start with the Knight. It doesn't have any props at all, and it's the easiest one to build:

import React from 'react'

export default function Knight() {
  return <span></span>
}

Yes, ♘ is the Unicode knight! It's gorgeous. We could've made its color a prop, but in our example we're not going to have any black knights, so there is no need for that.

It seems to render fine, but just to be sure, I immediately changed my entry point to test it:

import React from 'react'
import ReactDOM from 'react-dom'
import Knight from './Knight'

ReactDOM.render(<Knight />, document.getElementById('root'))
Screenshot

I'm going to do this every time I work on another component, so that I always have something to render. In a larger app, I would use a component playground like cosmos so I'd never write the components in the dark.

I see my Knight on the screen! Time to go ahead and implement the Square now. Here is my first stab:

import React from 'react'

export default function Square({ black }) {
  const fill = black ? 'black' : 'white'
  return <div style={{ backgroundColor: fill }} />
}

Now I change the entry point code to see how the Knight looks inside a Square:

import React from 'react'
import ReactDOM from 'react-dom'
import Knight from './Knight'
import Square from './Square'

ReactDOM.render(
  <Square black>
    <Knight />
  </Square>,
  document.getElementById('root'),
)

Sadly, the screen is empty. I made a few mistakes:

  • I forgot to give Square any dimensions so it just collapses. I don't want it to have any fixed size, so I'll give it width: '100%' and height: '100%' to fill the container.

  • I forgot to put {children} inside the div returned by the Square, so it ignores the Knight passed to it.

Even after correcting these two mistakes, I still can't see my Knight when the Square is black. That's because the default page body text color is black, so it is not visible on the black Square. I could have fixed this by giving Knight a color prop, but a much simpler fix is to set a corresponding color style in the same place where I set backgroundColor. This version of Square corrects the mistakes and works equally great with both colors:

import React from 'react'

export default function Square({ black, children }) {
  const fill = black ? 'black' : 'white'
  const stroke = black ? 'white' : 'black'

  return (
    <div
      style={{
        backgroundColor: fill,
        color: stroke,
        width: '100%',
        height: '100%',
      }}
    >
      {children}
    </div>
  )
}
Screenshot

Finally, time to get started with the Board! I'm going to start with an extremely naïve version that just draws the same single square:

import React from 'react'
import Square from './Square'
import Knight from './Knight'

export default function Board() {
  return (
    <div>
      <Square black>
        <Knight />
      </Square>
    </div>
  )
}

My only intention so far is to make it render, so that I can start tweaking it:

import React from 'react'
import ReactDOM from 'react-dom'
import Board from './Board'

ReactDOM.render(
  <Board knightPosition={[0, 0]} />,
  document.getElementById('root'),
)

Indeed, I can see the same single square. I'm now going to add a whole bunch of them! But I don't know where to start. What do I put in render? Some kind of a for loop? A map over some array?

To be honest, I don't want to think about it now. I already know how to render a single square with or without a knight. I also know the knight's position thanks to the knightPosition prop. This means I can write the renderSquare method and not worry about rendering the whole board just yet.

My first attempt at renderSquare looks like this:

function renderSquare(x, y, [knightX, knightY]) {
  const black = (x + y) % 2 === 1
  const isKnightHere = knightX === x && knightY === y
  const piece = isKnightHere ? <Knight /> : null

  return <Square black={black}>{piece}</Square>
}

I can already give it a whirl by changing the Board's rendering to be

export default function Board({ knightPosition }) {
  return (
    <div
      style={{
        width: '100%',
        height: '100%',
      }}
    >
      {renderSquare(0, 0, knightPosition)}
      {renderSquare(1, 0, knightPosition)}
      {renderSquare(2, 0, knightPosition)}
    </div>
  )
}
Screenshot

At this point, I realize that I forgot to give my squares any layout. I'm going to use Flexbox. I added some styles to the root div, and also wrapped the Squares into divs so I could lay them out. Generally it's a good idea to keep components encapsulated and ignorant of how they're being laid out, even if this means adding wrapper divs.

import React from 'react'
import Square from './Square'
import Knight from './Knight'

function renderSquare(i, [knightX, knightY]) {
  const x = i % 8
  const y = Math.floor(i / 8)
  const isKnightHere = x === knightX && y === knightY
  const black = (x + y) % 2 === 1
  const piece = isKnightHere ? <Knight /> : null

  return (
    <div key={i} style={{ width: '12.5%', height: '12.5%' }}>
      <Square black={black}>{piece}</Square>
    </div>
  )
}

export default function Board({ knightPosition }) {
  const squares = []
  for (let i = 0; i < 64; i++) {
    squares.push(renderSquare(i, knightPosition))
  }

  return (
    <div
      style={{
        width: '100%',
        height: '100%',
        display: 'flex',
        flexWrap: 'wrap',
      }}
    >
      {squares}
    </div>
  )
}
Screenshot

It looks pretty awesome! I don't know how to constrain the Board to maintain a square aspect ratio, but this should be easy to add later.

Think about it for a moment. We just went from nothing to being able to move the Knight on a beautiful Board by changing the knightPosition:

import React from 'react'
import ReactDOM from 'react-dom'
import Board from './Board'

ReactDOM.render(
  <Board knightPosition={[7, 4]} />,
  document.getElementById('root'),
)
Screenshot

The declarativeness is fantastic! That's why people love working with React.

Adding Game State

We want to make the Knight draggable. What we need in order to pull this off is to keep the current knightPosition in some kind of state storage, and have some way to change it.

Because setting up this state requires some thought, we won't try to implement dragging at the same time. Instead, we'll start with a simpler implementation. We will move the Knight when you click a particular Square, but only if this is allowed by the Chess rules. Implementing this logic should give us enough insight into managing the state, so we can replace clicking with the drag and drop once we've dealt with that.

React is not opinionated about the state management or the data flow; you can use Flux, Redux, Rx or even Backbone nah, avoid fat models and separate your reads from writes.

I don't want to bother with installing or setting up Redux for this simple example, so I'm going to follow a simpler pattern. It won't scale as well as Redux, but I also don't need it to. I have not decided on the API for my state manager yet, but I'm going to call it Game, and it will definitely need to have some way of signaling data changes to my React code.

Since I know this much, I can rewrite my index.js with a hypothetical Game that doesn't exist yet. Note that this time, I'm writing my code in blind, not being able to run it yet. This is because I'm still figuring out the API:

import React from 'react'
import ReactDOM from 'react-dom'
import Board from './Board'
import { observe } from './Game'

const root = document.getElementById('root')

observe(knightPosition =>
  ReactDOM.render(<Board knightPosition={knightPosition} />, root),
)

What is this observe function I import? It's just the most minimal way I can think of to subscribe to a changing state. I could've made it an EventEmitter but why on Earth even go there when all I need is a single change event? I could have made Game an object model, but why do that, when all I need is a stream of values?

Just to verify that this subscription API makes some sense, I'm going to write a fake Game that emits random positions:

export function observe(receive) {
  const randPos = () => Math.floor(Math.random() * 8)
  setInterval(() => receive([randPos(), randPos()]), 500)
}

It feels so good to be back in the rendering game!

Screenshot

This is obviously not very useful. If we want some interactivity, we're going to need a way to modify the Game state from our components. For now, I'm going to keep it simple and expose a moveKnight function that directly modifies the internal state. This is not going to fare well in a moderately complex app where different state storages may be interested in updating their state in response to a single user action, but in our case this will suffice:

let knightPosition = [0, 0]
let observer = null

function emitChange() {
  observer(knightPosition)
}

export function observe(o) {
  if (observer) {
    throw new Error('Multiple observers not implemented.')
  }

  observer = o
  emitChange()
}

export function moveKnight(toX, toY) {
  knightPosition = [toX, toY]
  emitChange()
}

Now, let's go back to our components. Our goal at this point is to move the Knight to a Square that was clicked. One way to do that is to call moveKnight from the Square itself. However, this would require us to pass the Square its position. Here is a good rule of thumb:

If a component doesn't need some data for rendering, it doesn't need that data at all.

The Square does not need to know its position to render. Therefore, it's best to avoid coupling it to the moveKnight method at this point. Instead, we are going to add an onClick handler to the div that wraps the Square inside the Board:

import React from 'react'
import Square from './Square'
import Knight from './Knight'
import { moveKnight } from './Game'

/* ... */

function renderSquare(i, knightPosition) {
  /* ... */
  return <div onClick={() => handleSquareClick(x, y)}>{/* ... */}</div>
}

function handleSquareClick(toX, toY) {
  moveKnight(toX, toY)
}

We could have also added an onClick prop to Square and used it instead, but since we're going to remove the click handler in favor of the drag and drop interface later anyway, why bother.

The last missing piece right now is the Chess rule check. The Knight can't just move to an arbitrary square, it is only allowed to make L-shaped moves. I'm adding a canMoveKnight(toX, toY) function to the Game and changing the initial position to A2 to match the Chess rules:

let knightPosition = [1, 7]

/* ... */

export function canMoveKnight(toX, toY) {
  const [x, y] = knightPosition
  const dx = toX - x
  const dy = toY - y

  return (
    (Math.abs(dx) === 2 && Math.abs(dy) === 1) ||
    (Math.abs(dx) === 1 && Math.abs(dy) === 2)
  )
}

Finally, I'm adding a canMoveKnight check to the handleSquareClick method:

import { canMoveKnight, moveKnight } from './Game'

/* ... */

function handleSquareClick(toX, toY) {
  if (canMoveKnight(toX, toY)) {
    moveKnight(toX, toY)
  }
}
Screenshot

Working great so far!

Adding Drag and Drop Interaction

This is the part that actually prompted me to write this tutorial. We are now going to see how easy React DnD makes it to add some drag and drop interaction to your existing components.

This part assumes you are at least somewhat familiar with the concepts presented in the overview, such as the backends, the collecting functions, the types, the items, the drag sources, and the drop targets. If you didn't understand everything, it's fine, but make sure you at least give it a chance before jumping into the coding process.

We're going to start by installing React DnD and the HTML5 backend for it:

yarn add react-dnd react-dnd-html5-backend

In the future, you might want to explore alternative third-party backends, such as the touch backend, but this is out of scope of this tutorial.

Setting up the Drag and Drop Context

The first thing we need to set up in our app is the DndProvider. This should be mounted near the top of our application. We need this to specify that we're going to use the HTML5Backend.

import React from 'react'
import { DndProvider } from 'react-dnd'
import HTML5Backend from 'react-dnd-html5-backend'

function Board() {
  /* ... */
  return <DndProvider backend={HTML5Backend}>...</DndProvider>
}

Define Drag Types

Next, I'm going to create the constants for the draggable item types. We're only going to have a single item type in our game, a KNIGHT. I'm creating a Constants module that exports it:

export const ItemTypes = {
  KNIGHT: 'knight',
}

The preparation work is done now. Let's make the Knight draggable!

Make the Knight Draggable

The useDrag hook accepts a specification object. In this object, item.type is set to the constant we just defined, so now we need to write a collecting function.

const [{ isDragging }, drag] = useDrag({
  item: { type: ItemTypes.KNIGHT },
  collect: monitor => ({
    isDragging: !!monitor.isDragging(),
  }),
})

Let's break this down:

  • useDrag accepts a specification object. The item.type property is required, and specifies the type of item being dragged. We could also attach extra information here to identify the kind of piece being dragged, but since this is a toy application we only need to define the type.
  • collect defines a collector function: this is basically a way to transform state from the drag-and-drop system into usable props for your components.
  • The result array contains

    • A props object as the first item - this contains the properties you collected from the drag-and-drop system.
    • A ref function as the second item. This is used to attach your DOM elements to react-dnd.

Let's take a look at the whole Knight component now, including the useDrag call and the updated render function:

import React from 'react'
import { ItemTypes } from './Constants'
import { useDrag } from 'react-dnd'

function Knight() {
  const [{isDragging}, drag] = useDrag({
    item: { type: ItemTypes.KNIGHT },
		collect: monitor => ({
			isDragging: !!monitor.isDragging(),
		}),
  })

  return (
    <div
      ref={drag}
      style={{
        opacity: isDragging ? 0.5 : 1,
        fontSize: 25,
        fontWeight: 'bold',
        cursor: 'move',
      }}
    ></div>,
  )
}

export default Knight
Screenshot

Make the Board Squares Droppable

The Knight is now a drag source, but there are no drop targets to handle the drop yet. We're going to make the Square a drop target now.

This time, we can't avoid passing the position to the Square. After all, how can the Square know where to move the dragged knight if the Square doesn't know its own position? On the other hand, it still feels wrong because the Square as an entity in our application has not changed, and if it used to be simple, why complicate it? When you face this dilemma, it's time to separate the smart and dumb components.

I'm going to introduce a new component called the BoardSquare. It renders the good old Square, but is also aware of its position. In fact, it's encapsulating some of the logic that the renderSquare method inside the Board used to do. React components are often extracted from such render submethods when the time is right.

Here is the BoardSquare I extracted:

import React from 'react'
import Square from './Square'

export default function BoardSquare({ x, y, children }) {
  const black = (x + y) % 2 === 1
  return <Square black={black}>{children}</Square>
}

I also changed the Board to use it:

/* ... */
import BoardSquare from './BoardSquare'

function renderSquare(i, knightPosition) {
  const x = i % 8
  const y = Math.floor(i / 8)
  return (
    <div key={i} style={{ width: '12.5%', height: '12.5%' }}>
      <BoardSquare x={x} y={y}>
        {renderPiece(x, y, knightPosition)}
      </BoardSquare>
    </div>
  )
}

function renderPiece(x, y, [knightX, knightY]) {
  if (x === knightX && y === knightY) {
    return <Knight />
  }
}

Let's now wrap the BoardSquare with a useDrop hook. I'm going to write a drop target specification that only handles the drop event:

const [, drop] = useDrop({
  accept: ItemTypes.KNIGHT,
  drop: () => moveKnight(x, y),
})

See? The drop method has the receives the props of the BoardSquare in scope, so it knows where to move the knight when it drops. In a real app, I might also use monitor.getItem() to retrieve the dragged item that the drag source returned from beginDrag, but since we only have a single draggable thing in the whole application, I don't need it.

In my collecting function I'm going to ask the monitor whether the pointer is currently over the BoardSquare so I can highlight it:

const [{ isOver, canDrop }, drop] = useDrop({
  accept: ItemTypes.KNIGHT,
  drop: () => moveKnight(x, y),
  collect: mon => ({
    isOver: !!mon.isOver(),
    canDrop: !!mon.canDrop(),
  }),
})

After changing the render function to connect the drop target and show the highlight overlay, here is what BoardSquare came to be:

import React from 'react'
import Square from './Square'
import { canMoveKnight, moveKnight } from './Game'
import { ItemTypes } from './Constants'
import { useDrop } from 'react-dnd'

function BoardSquare({ x, y, children }) {
  const black = (x + y) % 2 === 1
	const [{ isOver }, drop] = useDrop({
		accept: ItemTypes.KNIGHT,
		drop: () => moveKnight(x, y),
		collect: monitor => ({
			isOver: !!monitor.isOver(),
		}),
	})

  return (
    <div
      ref={drop}
      style={{
        position: 'relative',
        width: '100%',
        height: '100%',
      }}
    >
      <Square black={black}>{children}</Square>
      {isOver && (
        <div
          style={{
            position: 'absolute',
            top: 0,
            left: 0,
            height: '100%',
            width: '100%',
            zIndex: 1,
            opacity: 0.5,
            backgroundColor: 'yellow',
          }}
        />
      )}
    </div>,
  )
}

export default BoardSquare
Screenshot

This is starting to look good! There is just one change left to complete this tutorial. We want to highlight the BoardSquares that represent the valid moves, and only process the drop if it happened over one of those valid BoardSquares.

Thankfully, it is really easy to do with React DnD. I just need to define a canDrop method in my drop target specification:

const [{ isOver, canDrop }, drop] = useDrop({
  accept: ItemTypes.KNIGHT,
  canDrop: () => canMoveKnight(x, y),
  drop: () => moveKnight(x, y),
  collect: monitor => ({
    isOver: !!monitor.isOver(),
    canDrop: !!monitor.canDrop(),
  }),
})

I'm also adding monitor.canDrop() to my collecting function, as well as some overlay rendering code to the component:

import React from 'react'
import Square from './Square'
import { canMoveKnight, moveKnight } from './Game'
import { ItemTypes } from './Constants'
import { useDrop } from 'react-dnd'

function BoardSquare({ x, y, children }) {
  const black = (x + y) % 2 === 1
  const [{ isOver }, drop] = useDrop({
    accept: ItemTypes.KNIGHT,
    drop: () => moveKnight(x, y),
    canDrop: () => canMoveKnight(x, y),
    collect: monitor => ({
      isOver: !!monitor.isOver(),
      canDrop: !!monitor.canDrop(),
    }),
  })

  return (
    <div
      ref={drop}
      style={{
        position: 'relative',
        width: '100%',
        height: '100%',
      }}
    >
      <Square black={black}>{children}</Square>
      {isOver && !canDrop && <Overlay color="red" />}
      {!isOver && canDrop && <Overlay color="yellow" />}
      {isOver && canDrop && <Overlay color="green" />}
    </div>,
  )
}

export default BoardSquare
Screenshot

Add a Drag Preview Image

The last thing I want to demonstrate is drag preview customization. Sure, the browser will screenshot the DOM node, but what if we want to show a custom image?

We are lucky again, because it is easy to do with React DnD. We just need to use the preview ref provided by the useDrag hook.

const [{ isDragging }, drag, preview] = useDrag({
  item: { type: ItemTypes.KNIGHT },
  collect: monitor => ({
    isDragging: !!monitor.isDragging(),
  }),
})

This lets us connect up a dragPreview in render method, just like we used for drag items. react-dnd also provides a utility component, DragPreviewImage, which presents an image as a drag preview using this ref.

  const knightImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAVlpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IlhNUCBDb3JlIDUuNC4wIj4KICAgPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4KICAgICAgPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIKICAgICAgICAgICAgeG1sbnM6dGlmZj0iaHR0cDovL25zLmFkb2JlLmNvbS90aWZmLzEuMC8iPgogICAgICAgICA8dGlmZjpPcmllbnRhdGlvbj4xPC90aWZmOk9yaWVudGF0aW9uPgogICAgICA8L3JkZjpEZXNjcmlwdGlvbj4KICAgPC9yZGY6UkRGPgo8L3g6eG1wbWV0YT4KTMInWQAAOD1JREFUeAHtnQm8nHdZ75939pkzZ805OVtyktMkTZOmTZrupaWUlkJBBUSKKIJ6URBRP16vF71yBVHB+5ErcvWjotWiVJZ6QfbSUmhLpemSpkmaNHvOvi9zZt9n7vf3nx7oLXCygJBq3mTOzLz7++zP73n+/zE7v5ynwHkKnKfAeQqcp8B5CpynwHkKnKfAeQqcp8B5CpynwHkKnKfAeQqcp8DKFHj60Xsu/dB73/bJB+75+PUr7/nvuzXw73v6c//s9X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vs3q79z2Q1/Dg/nK2dmbPVBc6biY4UjqCC8SQyhCS4WZetDldxEBEkAwmRnlDfIXClMbjrnxLicspomckmvlGUKEBVSqvYeSL7VyfXbnYxcRWsGCtEomaNmHadCqWPodC+vln6ilwRRpFvvw0ugsfru4wRh/pqU4ceB/fcexz644pxiSSo23VQqLSKy8o/qj6OqQJvCgTgmcGZF5abykGWJaQ5IbDFlmQsO5K+ISXNJw9lr3XGbou5NuziPNkHaJIVqUKCp/cXMC873BKEEyIq7MptvNfV7+4nyQNIVf+vHouOQsMATQDJNXY7BSlUgxGORZagu/WZh96JWNM/z/f7+ryeKCEqHlZfmz3p//WVddXq93fV9et/xZIvn8z1r3nFeZ+wj6ElN7bqtV58GGCHdduw2OUeEjUi0CYF3cwjOzTn5C62VK5GyX1+ldu7k/vDcop/1ETPmlxvHap0FY9wud7KYu+EZuA4aFZsSZTFPXFaOkQe4cEg7XRKcb0rm4Gf7rKo4hir5w6ormpEgNpJhduB115gsgNcDNcnH4S6XsyV8Kxgb/iXMQSjaW/wcaEsvGjOMXYgAAAABJRU5ErkJggg==';
  render() {
    return (
      <>
        <DragPreviewImage connect={preview} src={knightImage} />
        <div
          ref={drag}
          style={{
            ...knightStyle,
            opacity: isDragging ? 0.5 : 1,
          }}
        ></div>
      </>
    )
  }
}

Concluding Words

This tutorial guided you through creating the React components, making design decisions about them and the application state, and finally adding the drag and drop interaction. The goal of this tutorial was to show you that React DnD fits great with the philosophy of React, and that you should think about the app architecture first before diving into implementing the complex interactions.

Happy dragging and dropping.

Screenshot

Now go and play with it!