simeydotme / sparticles

JavaScript Particles in Canvas ~~ Fast, Lightweight, High Performance.
https://sparticlesjs.dev
Mozilla Public License 2.0
248 stars 20 forks source link

ReactJS Support #24

Closed realav closed 2 years ago

realav commented 2 years ago

Hi, How to add this awesome library as a React component?

particles.js

import Sparticles from "sparticles";
import React, { useState, useEffect } from "react";

export default function Particles() {
  useEffect(() => {
    let mySparticles = new Sparticles({ color: "red", count: 10 }, 400, 300);
  });
  return <></>;
}

index.js

import Particles from "./particles";
export default function Nav() {

  return (
    <>
      <Particles />

    </>
  );
}

The particles did appear on my NextJS page but they always appear at the bottom. How to make them appear in the Header.

simeydotme commented 2 years ago

Hi,

Without a demo I can't say for sure, but it sounds like you need to set the position of the canvas. please read; https://github.com/simeydotme/sparticles#styling for instructions on how to do that.