Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poor performance using TRUNK #167

Open
simonbrage opened this issue Jul 6, 2023 · 0 comments
Open

Poor performance using TRUNK #167

simonbrage opened this issue Jul 6, 2023 · 0 comments

Comments

@simonbrage
Copy link

Using the TRUNK animation in my React app results in very poor performance by slowing down the app and impacting the responsiveness of buttons, etc. Any thoughts on what might cause this?

This is the page that includes the effect:

import React, { useState, useRef, useEffect } from "react";
import * as THREE from "three"; // Importing THREE.js
import TRUNK from "vanta/dist/vanta.trunk.min"; // Importing the vanta effect

export default function Home() {
    const [vantaEffect, setVantaEffect] = useState(0);
    const myRef = useRef(null);

    useEffect(() => {
      if(!vantaEffect) {
        TRUNK({
          THREE: THREE,
          el: myRef.current,
          color: 0x3B82F6,
          backgroundColor: 0xF9FAFB
        });
      }

  
      return () => {
        if (vantaEffect) {
          vantaEffect.destroy();
        }
      };
    }, [vantaEffect]);

    return (
      <section id="home" ref={myRef}>
        <div>
           {/* Buttons and text here */}
        </div>
      </section>
    );
  }

My App.js loads this page to make my React app navigable using react-router-dom:

import React from "react";
import { BrowserRouter, Routes, Route } from "react-router-dom";
import Home from "./components/Home";
import Navbar from "./components/Navbar";
import About from "./components/About";
import Projects from "./components/Projects";

export default function App() {
  return (
    <main>
      <BrowserRouter>
        <Navbar />
        <Routes>
          <Route path="/" element={<Home />} />
          <Route path="/about" element={<About />} />
          <Route path="/projects" element={<Projects />} />
        </Routes>
      </BrowserRouter>
      
    </main>
  );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant