Visx is a library that lets us add graphics to our React app easily.
In this article, we’ll look at how to use it to add a simple whiteboard into our React app.
We have to install a few modules.
To get started, we run:
npm i @visx/curve @visx/drag @visx/gradient @visx/responsive @visx/shape
to install the packages.
We can create the whiteboard by adding the items provided by the modules.
To do this, we write:
import React, { useCallback, useState } from "react";
import { LinePath } from "@visx/shape";
import { useDrag } from "@visx/drag";
import { curveBasis } from "@visx/curve";
import { LinearGradient } from "@visx/gradient";
function Example({ data = [], width, height }) {
const [lines, setLines] = useState(data);
const onDragStart = useCallback(
(currDrag) => {
setLines((currLines) => [
...currLines,
[{ x: currDrag.x, y: currDrag.y }]
]);
},
[setLines]
);
#programming #technology #web-development #javascript