From 1ad95f9c36de70d3149caf11ca8c90cd8491aacc Mon Sep 17 00:00:00 2001 From: Aaron Lampros Date: Fri, 18 Oct 2019 16:34:46 -0400 Subject: [PATCH 1/2] fix: use componentDidUpdate instead Fix #73 --- src/ReactConfetti.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ReactConfetti.tsx b/src/ReactConfetti.tsx index 69d2d02..4d3921e 100644 --- a/src/ReactConfetti.tsx +++ b/src/ReactConfetti.tsx @@ -30,7 +30,7 @@ class ReactConfettiInternal extends Component { } } - getSnapshotBeforeUpdate() { + componentDidUpdate() { const confettiOptions = extractCanvasProps(this.props)[0] if(this.confetti) { this.confetti.options = confettiOptions as IConfettiOptions From 607068a1845f4713ef6d5d13e24b8344df11985d Mon Sep 17 00:00:00 2001 From: Aaron Lampros Date: Fri, 18 Oct 2019 16:35:47 -0400 Subject: [PATCH 2/2] fix(types): make canvasRef optional Fix #72 --- src/ReactConfetti.tsx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/ReactConfetti.tsx b/src/ReactConfetti.tsx index 4d3921e..8bb3f2a 100644 --- a/src/ReactConfetti.tsx +++ b/src/ReactConfetti.tsx @@ -1,11 +1,9 @@ import React, { Component, CanvasHTMLAttributes } from 'react' import Confetti, { IConfettiOptions, confettiDefaults } from './Confetti' -export type Ref = HTMLCanvasElement +const ref = React.createRef() -export type Props = Partial & CanvasHTMLAttributes & { - canvasRef: React.RefObject -} +export type Props = Partial & CanvasHTMLAttributes & { canvasRef?: React.Ref } class ReactConfettiInternal extends Component { static readonly defaultProps = { @@ -16,7 +14,7 @@ class ReactConfettiInternal extends Component { constructor(props: Props, ...rest: any[]) { super(props, ...rest) - this.canvas = props.canvasRef || React.createRef() + this.canvas = props.canvasRef as React.RefObject || ref } canvas: React.RefObject = React.createRef() @@ -90,7 +88,7 @@ function extractCanvasProps(props: Partial | any): [Partial((props, ref) => ( +export const ReactConfetti = React.forwardRef((props, ref) => ( ))