react-canvas-draw, react-signature-canvas, react-signature-pad, and react-signature-pad-wrapper are React components designed to capture handwritten signatures or freeform drawings using the HTML5 canvas element. These libraries abstract the complexities of canvas event handling, stroke rendering, and image export, providing developers with ready-to-use signature pads. While react-canvas-draw offers general drawing capabilities with undo/redo features, the other three are specialized for signature capture and are built on top of the battle-tested signature_pad JavaScript library, differing mainly in their API design, additional utilities, and maintenance status.
When you need to capture user signatures or freehand drawings in a React application, several npm packages aim to solve this problem. While they all use the HTML <canvas> element under the hood, their APIs, feature sets, and maintenance status differ significantly. Letβs break down each option so you can choose the right tool for your project.
All four libraries wrap the native HTML5 canvas API to provide a drawing surface optimized for signature capture. They typically expose methods to clear the canvas, get image data (as PNG or base64), and control stroke appearance. However, their implementation strategies and extensibility vary.
react-canvas-drawThis package provides a general-purpose drawing canvas that can be configured for signatures but isnβt signature-specific. It supports undo/redo, brush radius control, and background images.
import CanvasDraw from "react-canvas-draw";
function App() {
return (
<CanvasDraw
brushRadius={2}
lazyRadius={0}
hideGrid={true}
canvasWidth={500}
canvasHeight={200}
/>
);
}
Note: The official npm page shows no recent updates, and the GitHub repository appears inactive. Use with caution in new projects.
react-signature-canvasA lightweight wrapper around the popular signature_pad library by Szymon Nowak. It focuses exclusively on signature capture with minimal overhead.
import SignatureCanvas from 'react-signature-canvas';
function App() {
const sigCanvas = useRef({});
const clear = () => sigCanvas.current.clear();
const trim = () => sigCanvas.current.getTrimmedCanvas().toDataURL('image/png');
return (
<div>
<SignatureCanvas
ref={sigCanvas}
canvasProps={{ width: 500, height: 200 }}
/>
<button onClick={clear}>Clear</button>
</div>
);
}
This package delegates most logic to signature_pad, which is actively maintained and well-tested.
react-signature-padAnother wrapper around signature_pad, but with a slightly different API design. It uses props instead of refs for common operations.
import { SignaturePad } from 'react-signature-pad';
function App() {
const [signaturePad, setSignaturePad] = useState(null);
const handleEnd = () => {
if (signaturePad) {
console.log(signaturePad.toDataURL());
}
};
return (
<SignaturePad
ref={setSignaturePad}
onEnd={handleEnd}
canvasProps={{ width: 500, height: 200 }}
/>
);
}
The package appears functional but has less documentation than alternatives.
react-signature-pad-wrapperThis is a higher-level wrapper that adds convenience features like built-in clear buttons, validation helpers, and TypeScript support on top of signature_pad.
import SignaturePadWrapper from 'react-signature-pad-wrapper';
function App() {
const [signature, setSignature] = useState('');
const handleSave = (dataURL) => {
setSignature(dataURL);
};
return (
<SignaturePadWrapper
onEnd={handleSave}
canvasProps={{ width: 500, height: 200 }}
clearButton={<button>Clear Signature</button>}
/>
);
}
Itβs designed to reduce boilerplate for common signature workflows.
react-canvas-draw: Built-in undo/redo via undo() and redo() methods.
// Requires ref access
canvasRef.current.undo();
react-signature-canvas: No native undo. Youβd need to implement it using fromData() and storing history yourself.
react-signature-pad: No undo support out of the box.
react-signature-pad-wrapper: No undo functionality.
If your app requires undo capability, react-canvas-draw is the only option among these four β but consider its maintenance status.
All packages support exporting as PNG/base64, but the method differs:
react-canvas-draw:
const data = canvasRef.current.getDataURL();
react-signature-canvas:
const data = sigCanvas.current.getTrimmedCanvas().toDataURL();
react-signature-pad:
const data = signaturePad.toDataURL();
react-signature-pad-wrapper:
// Via onEnd callback or by accessing internal ref
Note: Only react-signature-canvas and wrappers based on signature_pad support getTrimmedCanvas(), which crops whitespace β crucial for clean signature storage.
react-canvas-draw: Requires manual handling of window resize events.
react-signature-canvas: Responsive by default when container size changes; includes touch event support.
react-signature-pad: Inherits responsive behavior from signature_pad.
react-signature-pad-wrapper: Adds automatic resizing logic on top of signature_pad.
For mobile-first applications, the signature_pad-based solutions generally provide better out-of-the-box touch handling.
Based on official npm and GitHub sources:
react-canvas-draw: Last published over 3 years ago. Repository shows no recent activity. Not recommended for new projects.
react-signature-canvas: Actively maintained, with regular updates aligned with signature_pad releases.
react-signature-pad: Appears functional but has sparse documentation and infrequent updates.
react-signature-pad-wrapper: Actively maintained, with clear TypeScript definitions and recent feature additions.
Avoid react-canvas-draw unless youβre maintaining a legacy codebase that already depends on it.
You need a clean signature pad with clear button and trimmed output for legal documents.
react-signature-canvas or react-signature-pad-wrapperYouβre building a sketching tool where users expect undo functionality.
react-canvas-draw β but consider forking or migrating to a more modern canvas library like roughjs or fabric.js with React bindings.You need full type safety and long-term maintainability.
react-signature-pad-wrapper (includes .d.ts files) or react-signature-canvas (community types available via DefinitelyTyped).| Feature | react-canvas-draw | react-signature-canvas | react-signature-pad | react-signature-pad-wrapper |
|---|---|---|---|---|
Based on signature_pad | β | β | β | β |
| Trimmed output | β | β | β | β |
| Undo/Redo | β | β | β | β |
| Active maintenance | β (deprecated) | β | β οΈ (minimal activity) | β |
| Built-in clear button | β | β | β | β |
| TypeScript support | β | β οΈ (via @types) | β οΈ | β |
For new projects, avoid react-canvas-draw due to inactivity. Between the remaining three:
react-signature-canvas if you want a minimal, direct wrapper with full control.react-signature-pad-wrapper if you prefer convenience features (like built-in clear buttons and validation helpers) and strong TypeScript support.react-signature-pad only if its specific API fits your architecture β but verify compatibility thoroughly.Remember: All signature_pad-based solutions benefit from the robustness of the underlying library, which handles edge cases like high-DPI displays, touch events, and smooth stroke rendering. That shared foundation makes them more reliable than standalone implementations.
Avoid react-canvas-draw for new projects β it hasn't been actively maintained in years and lacks signature-specific features like automatic whitespace trimming. Only consider it if you're maintaining an existing codebase that already depends on it and requires undo/redo functionality not easily replicated elsewhere.
Choose react-signature-canvas when you need a lightweight, direct wrapper around the proven signature_pad library with minimal abstraction. It gives you full control over the canvas instance via refs and is ideal if you prefer to build your own UI controls (like clear buttons) and handle responsiveness manually.
Consider react-signature-pad if its prop-based API aligns with your component design patterns, but verify its compatibility and maintenance status carefully. It offers core signature functionality but provides less documentation and fewer convenience features compared to alternatives, making it a riskier choice for production applications.
Opt for react-signature-pad-wrapper when you want a batteries-included solution with built-in UI elements (like clear buttons), automatic canvas resizing, TypeScript support, and validation helpers. It reduces boilerplate for common signature workflows while leveraging the reliability of the underlying signature_pad library.
A simple yet powerful canvas-drawing component for React (Demo)
Install via NPM:
npm install react-canvas-draw --save
or YARN:
yarn add react-canvas-draw
import React from "react";
import ReactDOM from "react-dom";
import CanvasDraw from "react-canvas-draw";
ReactDOM.render(<CanvasDraw />, document.getElementById("root"));
For more examples, like saving and loading a drawing ==> look into the /demo/src folder.
These are the defaultProps of CanvasDraw. You can pass along any of these props to customize the CanvasDraw component. Examples of how to use the props are also shown in the /demo/src folder.
static defaultProps = {
onChange: null
loadTimeOffset: 5,
lazyRadius: 30,
brushRadius: 12,
brushColor: "#444",
catenaryColor: "#0a0302",
gridColor: "rgba(150,150,150,0.17)",
hideGrid: false,
canvasWidth: 400,
canvasHeight: 400,
disabled: false,
imgSrc: "",
saveData: null,
immediateLoading: false,
hideInterface: false,
gridSizeX: 25,
gridSizeY: 25,
gridLineWidth: 0.5,
hideGridX: false,
hideGridY: false
enablePanAndZoom: false,
mouseZoomFactor: 0.01,
zoomExtents: { min: 0.33, max: 3 },
};
Useful functions that you can call, e.g. when having a reference to this component:
getSaveData() returns the drawing's save-data as a stringified objectloadSaveData(saveData: String, immediate: Boolean) loads a previously saved drawing using the saveData string, as well as an optional boolean flag to load it immediately, instead of live-drawing it.getDataURL(fileType, useBgImage, backgroundColour) will export the canvas to a data URL, which can subsequently be used to share or manipulate the image file.clear() clears the canvas completely, including previously erased lines, and resets the view. After a clear, undo() will have no effect.eraseAll() clears the drawn lines but retains their data; calling undo() can restore the erased lines. Note: erased lines are not included in the save data.resetView() resets the canvas' view to defaults. Has no effect if the enablePanAndZoom property is false.undo() removes the latest change to the drawing. This includes everything drawn since the last MouseDown event.This repo was kickstarted by nwb's awesome react-component starter.
You just need to clone it, yarn it & start it!
If you want to save large strings, like the stringified JSON of a drawing, I recommend you use pieroxy/lz-string for compression. It's LZ compression will bring down your long strings to only ~10% of its original size.
The lazy-brush project as well as its demo app by dulnan have been a heavy influence.
I borrowed a lot of the logic and actually used lazy-brush during the push to v1 of react-canvas-draw. Without it, react-canvas-draw would most likely still be pre v1 and wouldn't feel as good.
Thanks goes to these wonderful people (emoji key):
Martin Beierling-Mutz π» π π‘ π€ | Jan Hug π€ |
|---|
This project follows the all-contributors specification. Contributions of any kind welcome!
MIT, see LICENSE for details.