Skip to content

Commit

Permalink
fix(types): make canvasRef optional
Browse files Browse the repository at this point in the history
Fix #72
  • Loading branch information
alampros committed Oct 18, 2019
1 parent 1ad95f9 commit 607068a
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/ReactConfetti.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import React, { Component, CanvasHTMLAttributes } from 'react'
import Confetti, { IConfettiOptions, confettiDefaults } from './Confetti'

export type Ref = HTMLCanvasElement
const ref = React.createRef<HTMLCanvasElement>()

export type Props = Partial<IConfettiOptions> & CanvasHTMLAttributes<HTMLCanvasElement> & {
canvasRef: React.RefObject<HTMLCanvasElement>
}
export type Props = Partial<IConfettiOptions> & CanvasHTMLAttributes<HTMLCanvasElement> & { canvasRef?: React.Ref<HTMLCanvasElement> }

class ReactConfettiInternal extends Component<Props> {
static readonly defaultProps = {
Expand All @@ -16,7 +14,7 @@ class ReactConfettiInternal extends Component<Props> {

constructor(props: Props, ...rest: any[]) {
super(props, ...rest)
this.canvas = props.canvasRef || React.createRef<HTMLCanvasElement>()
this.canvas = props.canvasRef as React.RefObject<HTMLCanvasElement> || ref
}

canvas: React.RefObject<HTMLCanvasElement> = React.createRef()
Expand Down Expand Up @@ -90,7 +88,7 @@ function extractCanvasProps(props: Partial<IConfettiOptions> | any): [Partial<IC
return [confettiOptions, rest, refs]
}

export const ReactConfetti = React.forwardRef<Ref, Props>((props, ref) => (
export const ReactConfetti = React.forwardRef<HTMLCanvasElement, Props>((props, ref) => (
<ReactConfettiInternal canvasRef={ref} {...props} />
))

Expand Down

0 comments on commit 607068a

Please sign in to comment.