diff --git a/README.md b/README.md index 2b8d4dd..f36863f 100644 --- a/README.md +++ b/README.md @@ -35,15 +35,16 @@ npm i -S react-signature-canvas ## Usage -```javascript +```jsx import React from 'react' -import ReactDOM from 'react-dom' +import { createRoot } from 'react-dom/client' import SignatureCanvas from 'react-signature-canvas' -ReactDOM.render( +createRoot( + document.getElementById('my-react-container') +).render( , - document.getElementById('react-container') ) ``` @@ -80,10 +81,17 @@ Of these props, all, except for `canvasProps` and `clearOnResize`, are passed th ### API -All API methods require a ref to the SignatureCanvas in order to use and are instance methods of the ref. +All API methods require [a ref](https://react.dev/learn/manipulating-the-dom-with-refs) to the SignatureCanvas in order to use and are instance methods of the ref. -```javascript - { this.sigCanvas = ref }} /> +```jsx +import React, { useRef } from 'react' +import SignatureCanvas from 'react-signature-canvas' + +function MyApp() { + const sigCanvas = useRef(null); + + return +} ``` - `isEmpty()` : `boolean`, self-explanatory diff --git a/example/src/index.js b/example/src/index.js index fef9101..9816df1 100644 --- a/example/src/index.js +++ b/example/src/index.js @@ -1,46 +1,36 @@ -import React, { Component } from 'react' +import React, { useState, useRef } from 'react' import { createRoot } from 'react-dom/client' -import SignaturePad from '../../src/index.tsx' +import SignatureCanvas from '../../src/index.tsx' import * as styles from './styles.module.css' -class App extends Component { - state = { trimmedDataURL: null } +function App () { + const sigCanvas = useRef(null) + const [trimmedDataURL, setTrimmedDataURL] = useState(null) - sigPad = {} - - clear = () => { - this.sigPad.clear() + function clear () { + sigCanvas.current.clear() } - trim = () => { - this.setState({ - trimmedDataURL: this.sigPad.getTrimmedCanvas().toDataURL('image/png') - }) + function trim () { + setTrimmedDataURL(sigCanvas.current.getTrimmedCanvas().toDataURL('image/png')) } - render () { - const { trimmedDataURL } = this.state - return
+ return ( +
- { this.sigPad = ref }} /> +
- - + +
{trimmedDataURL - ? signature + ? signature : null}
- } + ) } createRoot(document.getElementById('container')).render() diff --git a/example/src/styles.module.css b/example/src/styles.module.css index 682d423..6d7d97b 100644 --- a/example/src/styles.module.css +++ b/example/src/styles.module.css @@ -19,7 +19,7 @@ body { background-color: #fff; } -.sigPad { +.sigCanvas { width: 100%; height: 100%; } diff --git a/package.json b/package.json index d68be3f..f9c8e47 100644 --- a/package.json +++ b/package.json @@ -112,10 +112,5 @@ "jest-environment-jsdom": { "canvas": "$canvas" } - }, - "ts-standard": { - "ignore": [ - "example" - ] } }