Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
alampros committed Oct 18, 2019
2 parents 15911b1 + 607068a commit 5392c2a
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 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 All @@ -30,7 +28,7 @@ class ReactConfettiInternal extends Component<Props> {
}
}

getSnapshotBeforeUpdate() {
componentDidUpdate() {
const confettiOptions = extractCanvasProps(this.props)[0]
if(this.confetti) {
this.confetti.options = confettiOptions as IConfettiOptions
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 5392c2a

Please sign in to comment.