A step-by-step guide to successfully integrate vantajs wave in your React application

My problem involves using the vantajs wave library. I want to figure out how to make the waves continue rendering on a specific CSS selector even after clicking through the tablinks of my react app. However, I encounter an error when using Brave browser that says: "three.r92.min.js:28 Uncaught TypeError: Cannot read property 'precision' of null". Initially, the wave doesn't render at all.

Interestingly, if I switch to Google Chrome and check the background of my selected element, I can see the wave effect that I implemented from .

However, the issue arises when I switch from the home tab to another tab, and then return to the home tab where my selected element resides. The wave effect is no longer visible behind the selected element, and the error message displayed is: "vanta.waves.min.js:161 [VANTA] Cannot find element .showcase__container".

Below is the HTML code:

    <meta charset='utf-8' lang="EN-US">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <script src="./src/three.r92.min.js"></script>
    <script src="https://www.vantajs.com/dist/vanta.waves.min.js"></script>
    <link rel="stylesheet" href="./css/style.css">
    <title>DigitalWebFlex</title>
</head>
<body>
        <div id='root'></div>
    <script type='text/javascript' src='/dist/bundle.js' charset='utf-8'></script>
        <script>
            VANTA.WAVES('#showcase__container');
        </script>
</body>

And here is the React code:

            <div className="showcase__container" id="showcase__container">

                <button className="button button--animated button--white" onClick={this.setPagePortfolio}>Portfolio</button>

            </div>

Thank you in advance!

Answer №1

Hey there! If you want to install Vanta, simply run the command npm i vanta

Additionally, make sure to include three.js in the head section of your HTML document.

Once you have done that, you can use the following code:

import React from 'react'
import WAVES from 'vanta/dist/vanta.waves.min'

class MyComponent extends React.Component {
  constructor() {
    super()
    this.vantaRef = React.createRef()
  }
  componentDidMount() {
    this.vantaEffect = WAVES({
      el: this.vantaRef.current
    })
  }
  componentWillUnmount() {
    if (this.vantaEffect) this.vantaEffect.destroy()
  }
  render() {
    return (
    <div ref={this.vantaRef}>
      /* Your foreground content goes here */
    </div>
    )
  }
}

This guide should assist you in installing and using Vanta. For a more detailed explanation, you can refer to this page or check out the Vanta.js README.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Revamp Material UI Expansion Panel Summary

expansionPanelSummary: { content: { "& > :last-child": { paddingRight: 0 } }, expandIcon: { top: "80%" } } I'm attempting to customize the styles of Materi ...

Content on the website has vanished into thin air

Attempting to retrieve the content of a webpage located at The source code of this page reveals an element labeled "row_1"... However, when attempting to achieve this in my code: reader = new BufferedReader(new InputStreamReader(connection.getInputStrea ...

Preventing Redropping: A jQuery Drag and Drop Feature to Ensure Dropped Elements Stay Put

After implementing Drag & Drop functionality using jQuery, I have encountered a specific issue. The problem: When the dropped element (drag 1) is removed from the droppable container, it reverts back to the draggable container. Subsequently, attempting to ...

Facing continuous 404 errors while working with nodejs and express

While attempting to collect data from a local host webpage's registration form that captures user information, I encounter an issue upon pressing the submit button A 404 Error is displayed stating "page not found", preventing the collection and out ...

Every time I attempt to set up Material-UI, a barrage of errors is thrown my way, making the installation process frustrating

After successfully installing React using npx, I encountered issues when trying to install Material-UI. Below is the code snippet that shows the errors: npm install @material-ui/core npm WARN saveError ENOENT: no such file or directory, open '/Users ...

What are the necessary steps to launch Next.js without relying on Vercel's platform?

Looking to deploy a Next.js app, but not on Vercel. What is the process for deploying it? In the past, I would drag and drop the build folder from React to the server, but with Next.js I am unsure of which files need to be deployed and how. Note: I am ut ...

`I am unable to insert an image into PrimeReact`

I am struggling to integrate images into the dashboard using primereact. Despite placing my photo folder in the public directory and entering the correct photo path, the image is not displaying on the page. I have attempted numerous methods but have been ...

Html elements overlapping due to incorrect positioning

I'm having an issue with my div elements on a web page. Despite them being set up separately, they all end up positioned underneath the first div created (SiteFullControl). Is there any solution to prevent this from happening? <div id="SiteFullCo ...

Creating HTTP-only cookies within a NextJS middleware

Having an issue with updating access token in my middleware when the current one expires; here's my approach: Generate a new token Send it to an API route which adds the token to its response header. The problem arises when the middleware receives t ...

Ensure that each value in the MUI autocomplete appears on a separate line

I am working with a multi-select MUI Autocomplete component and I want the selected options to appear on separate lines for better readability, but I'm not sure how to achieve this. Currently, it looks like this: https://i.stack.imgur.com/PzOak.png ...

unexpected alteration of text sizing in mathjax within reveal.js presentations

Something strange is happening with the font size in my slides. The code for each slide is the same, but there is an unexpected change between the 3rd and 4th slide. I cannot figure out what is causing this discrepancy. Oddly enough, when I remove the tit ...

Socket.io is unable to function properly when when using the on event ("connection")

I am trying to incorporate socket-io into my project and have set it up on both the server (node-js) and the client (react). However, I am encountering issues as it doesn't seem to work properly. In the server console, I am unable to see the message u ...

Using identical class names in different components was not possible as the CSS was not being contained within the styled component's scope

I am encountering a frustrating issue that seems to defy the essence of CSS in JS. The problem arises when I use styled-components and attempt to apply a classname that is already used higher up in the React component tree within a styled component. Surpri ...

Designing a carousel-style menu list with navigation buttons for moving forward and backward

I'm running into some trouble while attempting to create a carousel. Firstly, the issue I am facing is that when you continuously click on the Next button, the function keeps working even after reaching the last item. I'm not sure how to make th ...

Maintaining the proportions of divs containing background images

I'm dealing with a background image that features a large blue diagonal line where we want our content to align. However, I'm encountering difficulties in maintaining the alignment of the content as it resizes (resulting in the background diagon ...

Encountering an issue with obtaining an undefined value for a URL query parameter when attempting to directly access a

Using the Next.js framework, I have a link in the index.js file (for the client lists page) like this: <Link href={{pathname: '/tickets/[id]', query: {id: rowData.id}}}> <Button icon='pi pi-eye' /> </Link> In the [i ...

Configuring Node.js and express.js for my personal website to showcase my projects

I am new to node.js and I'm excited to implement it on my personal website as a way to start learning. I have successfully set up the node server, but I am struggling with setting up routing using express.js. All my files are typical static files like ...

Customize Individual Rows in a React DataGrid

I am exploring the world of Material UI React data grid for the first time, and I am looking to add a unique background color to only the initial three rows. Each row should have a different color scheme that remains static, without any interactions trigge ...

Manipulate Attributes in Javascript

Having an issue here - I'm trying to use JavaScript to set some attributes. for(i=0;i<div_navi.childNodes.length;i++){ if(div_navi.childNodes[i].nodeName =="SPAN"){ div_navi.childNodes[i].setAttribute("onclick","g ...

Enhanced browsing experience with personalized search suggestions

As a developer, I am aware that you have the ability to customize the browser's suggestions for various fields. For example, specifying that a field is for email and only suggesting values for email fields in the future. Is this functionality really ...