Better Programming

Advice for programmers.

Follow publication

Member-only story

How to Make a Whiteboard App with React Konva

John Au-Yeung
Better Programming
Published in
14 min readSep 4, 2019

--

Photo by Austin Distel on Unsplash

The HTML Canvas is part of the HTML specification that allows developers to easily add graphics and interactivity to their apps.

In the HTML Canvas, you can add images, text, and shapes with different colors, fills, and gradients. It is supported by almost all recent browsers.

To add something to a canvas, you first add a canvas element to your page. Then, you can add lines to your canvas in the shape that you want.

For example, to add a line and a circle to your canvas element, in your HTML file you do the following:

<canvas id="canvas" width="200" height="100" style="border:2px solid #000000;">
</canvas>

Then, in your JavaScript file, you do this:

let c = document.getElementById("canvas");
let ctx = c.getContext("2d");
ctx.moveTo(0, 0);
ctx.lineTo(50, 100);
ctx.stroke();
ctx.beginPath();
ctx.arc(1, 50, 40, 0, 2 * Math.PI);
ctx.stroke();

If you want to add anything more complex, it will be difficult to do.

Therefore, the Konva library abstracts the hard work of adding items to the canvas. It allows you to add many more shapes by simply writing a few lines of code. There are also React bindings for Konva, which has abstracts with additional functionality. However, the feature set of React…

--

--

Responses (4)

Write a response