Search code examples
javascriptreactjsparticles.jsreact-particles-js

Particle.js not showing particles on ReactJS website


I have been trying to implement Particles.js on my portfolio website but have been rather unsuccessful. This is the following line of code I have run in my library to get it running:

npm i react-tsparticles

I couldn't add this package to my website so i tried to add this to a new project. i tried 2 different tutorial video to add it but it didn't work out. These are the videos
https://www.youtube.com/watch?v=F20SxgG5MlM
https://www.youtube.com/watch?v=NO76xNYkNGk&t

This is how my page looks right now

This is how my page should look

This is my configuration file for particles

const particlesConfig = {
  background: {
    color: "#6f32a8"
  },
  fullScreen: {
    enable: true,
    zIndex: -1
  },
  particles: {
    number: {
      value: 80,
      density: {
        enable: true,
        value_area: 800
      }
    },
    color: {
      value: "#ffffff"
    },
    shape: {
      type: "circle",
      stroke: {
        width: 0,
        color: "#000000"
      },
      polygon: {
        nb_sides: 5
      },
      image: {
        src: "img/github.svg",
        width: 100,
        height: 100
      }
    },
    opacity: {
      value: 0.5,
      random: false,
      anim: {
        enable: false,
        speed: 1,
        opacity_min: 0.1,
        sync: false
      }
    },
    size: {
      value: 3,
      random: true,
      anim: {
        enable: false,
        speed: 40,
        size_min: 0.1,
        sync: false
      }
    },
    line_linked: {
      enable: true,
      distance: 150,
      color: "#ffffff",
      opacity: 0.4,
      width: 1
    },
    move: {
      enable: true,
      speed: 3,
      direction: "none",
      random: false,
      straight: false,
      out_mode: "out",
      bounce: false,
      attract: {
        enable: false,
        rotateX: 600,
        rotateY: 1200
      }
    }
  },
  interactivity: {
    detect_on: "canvas",
    events: {
      onhover: {
        enable: false,
        mode: "repulse"
      },
      onclick: {
        enable: false,
        mode: "push"
      },
      resize: true
    },
    modes: {
      grab: {
        distance: 400,
        line_linked: {
          opacity: 1
        }
      },
      bubble: {
        distance: 400,
        size: 40,
        duration: 2,
        opacity: 8,
        speed: 3
      },
      repulse: {
        distance: 200,
        duration: 0.4
      },
      push: {
        particles_nb: 4
      },
      remove: {
        particles_nb: 2
      }
    }
  },
  retina_detect: true
};
export default particlesConfig;


This is my background component

import React from 'react';
import Particles from "react-tsparticles";
import particlesConfig from '../config/particles-config.js';

const particleBackground = () => {
  return (
    <Particles options={particlesConfig} height="50vh" width='50vw'/>
  )
}

export default particleBackground


And this is my App component

import React from "react";
import ParticleBackground from "./components/ParticleBackground";
import "./App.css"
const App = () => {
  return (
  <div className="App">
    <ParticleBackground/>
    <div className="particlesheader">
      <h1>Particle.JS</h1>
    </div>
  </div>
  );
};

export default App;

Hope you guys can help me out! Thanks!


Solution

  • I think there is problem with latest version of react-tsparticles.
    this codesandbox react-tsparticles template using version 1.40.2 but latest version for react-tsparticles is 2.0.6. I uninstalled 1.40.2 in codesandbox and installed 2.0.6 and i realized the problem is about new versions.
    So i installed the version 1.40.2 in my project and it's working right now.