Skip to content

Commit

Permalink
fix component
Browse files Browse the repository at this point in the history
  • Loading branch information
matteobruni committed May 17, 2020
1 parent e6d88f4 commit ba979b8
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/Particles.tsx
@@ -1,12 +1,12 @@
import * as React from "react";
import { Component } from "react";
import isEqual from 'lodash/isEqual';
import isEqual from "lodash/isEqual";
import type { IOptions } from "tsparticles/dist/Interfaces/Options/IOptions";
import { Container } from "tsparticles/dist/Classes/Container";
import type { RecursivePartial } from "tsparticles/dist/Types/RecursivePartial";
import { defaultParams } from "./DefaultOptions";
import { Options } from "tsparticles/dist/Classes/Options/Options";
import { tsParticles } from "tsparticles/dist/index";
import { tsParticles } from "tsparticles";

export interface ParticlesProps {
id: string;
Expand Down Expand Up @@ -49,12 +49,13 @@ export default class Particles extends Component<ParticlesProps,
} catch {
return null;
} // SSR
var options = new Options();
const options = new Options();

options.load(defaultParams);
options.load(params);

tsParticles.dom();
tsParticles.init();

const container = new Container(tagId, options);

if (this.props.particlesRef) {
Expand All @@ -69,8 +70,8 @@ export default class Particles extends Component<ParticlesProps,
if (canvas) {
this.destroy();
this.setState({
library: this.buildParticlesLibrary(props.id, props.params)
},
library: this.buildParticlesLibrary(props.id, props.params)
},
() => {
this.loadCanvas(canvas);
}
Expand All @@ -87,8 +88,8 @@ export default class Particles extends Component<ParticlesProps,
loadCanvas(canvas: HTMLCanvasElement) {
if (canvas) {
this.setState({
canvas
},
canvas
},
() => {
const { library } = this.state;

Expand All @@ -104,7 +105,7 @@ export default class Particles extends Component<ParticlesProps,
}

shouldComponentUpdate(nextProps: Readonly<ParticlesProps>) {
return !isEqual(nextProps, this.props);
return !this.state.library || !isEqual(nextProps, this.props);
}

componentDidUpdate() {
Expand Down

0 comments on commit ba979b8

Please sign in to comment.