Skip to content

Commit

Permalink
Update ref handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanhefner committed Jul 13, 2023
1 parent 18e68bf commit 39e91a7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -28,7 +28,7 @@ yarn add react-canvas-wrapper

**Properties**

* `canvasRef:Function` - Function to set reference to `<canvas>` element. (Default: `(element) => { this.canvas = element; }`)
* ~`canvasRef:Function` - Function to set reference to `<canvas>` element. (Default: `(element) => { this.canvas = element; }`)~ _**Note:** This can now be done by passing a simple `ref` prop. like you normally would in React.
* `draw:Function` - Callback called when props change on the component. (Default: `(canvas) => {}`)
* `width:Number` - Width of the canvas @ 1x. (Default: `30`)
* `height:Number` - Height of the canvas @ 1x. (Default: `30`)
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Expand Up @@ -26,7 +26,7 @@ const Canvas = forwardRef((props, ref) => {
const internalRef = ref || useRef();

useEffect(() => {
draw(internalRef);
draw(internalRef.current);
}, [JSON.stringify(props)]);

const styleProp = useMemo(() => {
Expand Down
14 changes: 14 additions & 0 deletions types/index.d.ts
@@ -0,0 +1,14 @@
import React from 'react'

/**
* Canvas
*/

export interface CanvasProps {
width?: number;
height?: number;
pixelRatioAware?: boolean;
draw?: (canvas: React.RefObject<HTMLCanvasElement>) => void;
}

export class Canvas extends React.Component<CanvasProps> {}
11 changes: 11 additions & 0 deletions types/tsconfig.json
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noEmit": true
}
}

0 comments on commit 39e91a7

Please sign in to comment.