Issue with React Js: Text Sphere not appearing on page reload

Currently immersed in a react.js environment and eager to incorporate this impressive animated text sphere. Utilizing the TagCloud package for rendering assistance, however, encountered an issue where the text sphere would only display once and disappear upon webpage reload.

Despite exploring resources like this video tutorial in attempts to resolve the problem, the sphere still vanishes after reloading the page. On another note, making edits to my TextSphere component while the react app is running results in an unexpected duplicate of the text sphere appearing on the webpage. Below, I will provide my code for reference. Thank you in advance for any assistance.

react js component:

import React, { useEffect }from "react";
import TagCloud from "TagCloud";

const TextSphere = () => {
    useEffect(() => {
        return () => {
            const container = ".tagcloud";
            const texts = [
                 'JavaScript', 
                 'CSS', 
                 'HTML',
                 'C', 
                 'C++', 
                 'React',
                 'Python', 
                 'Java',
                 'MySQL',
                 'jQuery',
            ];

            const options = {
                radius: 300,
                maxSpeed: "normal",
                initSpeed: "normal",
                keep: true,
            };

            TagCloud(container, texts, options);
        };
    }, []);

    return (
        <div className="text-sphere">
            <span className="tagcloud"></span>
        </div>
    );
};

export default TextSphere;

CSS file -

.text-sphere {
    position: relative;
    top: 0;
    width: 100%;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.tagcloud {
    display: inline-block;
    top: 0;
    left: 0;
    font-weight: 600;
    letter-spacing: 0.0625em;
    font-size: 1.3em;
}

.tagcloud--item {
    color: black;
    text-transform: uppercase;
}

.tagcloud--item:hover {
    color: rgb(224, 167, 101);
}

Answer №1

import React, { useEffect, useRef } from "react";
import TagCloud from "TagCloud";
import "./TextSphere.css";

const TextSphereComponent = () => {
  const containerReference = useRef(null);

  useEffect(() => {
    const textContainer = containerReference.current;
    const wordList = [
      "Java",
      "Python",
      "HTML",
      "CSS",
      "JavaScript",
      "React",
      "NodeJs",
      "MongoDb",
      "SQL",
      "Git",
      "GitHub",
      "Docker",
    ];
    const configuration = {
      radius: 300,
      maxSpeed: "normal",
      initSpeed: "normal",
      keep: true,
      loop: true,
      lockX: true,
      lockY: true,
    };

    TagCloud(textContainer, wordList, configuration);

    return () => {
      TagCloud(textContainer, [], {});
    };
  }, []);

  return (
    <div className="text-sphere-container">
      <span className="sphere-tagcloud" ref={containerReference}></span>
    </div>
  );
};

export default TextSphereComponent;

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

Creating a dynamic dropdown menu using JQuery that does not automatically submit the form when a value is

Upon selecting a background color from the dropdown menu, I am generating a dynamic dropdown for text colors. The Text Color dropdown is populated correctly based on the selection of Background Color. Although the functionality works as intended, I encoun ...

The Vue component should trigger the display of data in a Bootstrap modal based on the row of the button that was

Here is a sample code snippet demonstrating how data is fetched from the database: <table class="table table-bordered"> <thead> <tr><th>User ID</th><th>Account Number</th><th>Accou ...

The Swiper JS component is experiencing flickering and is not functioning properly within the Next JS 13 app router

I'm currently facing some challenges with integrating a simple swiper into my Next.js website (v13 with app router). Initially, I attempted to import the swiper as usual by copying the code from a demo on their official website. While the swiper show ...

Scrolling with React Event

I am attempting to create a scrollbar that only appears when I scroll within a particular area using React. I am utilizing debounce and useState in my implementation. The issue: When I reach the end of the scroll, the event continues to repeat indefinitel ...

Maximizing the width of an absolute div element inside a container

Looking at this demo, you'll notice that the header remains fixed. However, my issue lies in getting the absolute <div> inside the <th> to occupy 100% of the width of the <th> When I set width: 100% for the <div>, it expands t ...

Best Method for Updating a Single Scope and Setting the Others to False in AngularJS

If I have 4 fields in my view that need to be toggled open or closed when clicked, with the requirement of closing the other three, how can this be achieved without duplicate code? <div class="square red"></div> <div class="square blue"> ...

show the stored value inside the useRef variable

One of my challenges involves a variable const prediction = useRef<any>(null); A button triggers a function that updates the variable's value: function showResult() { classifier.current.classify(capture, (result) => { ...

Steps for implementing an <h1> element with the React Material UI theme

I have chosen the 'dark' theme and would like to apply it to an h1 element. How can I achieve this? The method below does not yield the desired result: <MuiThemeProvider theme={theme}> <h1>Page Title</h1> ... The following ...

What is the best way to send a parameter from jQuery to PHP?

I am trying to create a simple button that, when clicked, will pass a value from jQuery to a PHP file for execution. The idea is that when the button is clicked, it triggers an onclick event which sends the number "1" to the jQuery code. Then, jQuery shoul ...

Exploring Node troubleshooting with WebPack and Feathers

Currently, I am part of a team working on a project that involves using Node, Webpack, TypeScript, and Express/Feathers. While my fellow developers are experienced in these technologies, I have limited experience with JavaScript mainly on the client-side a ...

What could be causing the d3.js pie chart transition to malfunction?

Today I am experimenting with d3.js to create a unique pie chart from scratch. While following tutorials here as my base, there were modifications made in the code to add personal touches and customization. The challenge arose during Step 6 when introduc ...

The nested table is overflowing beyond the boundaries of its outer parent table

I have created a nested table, shown below: <table border="0" width="750" cellspacing="0" cellpadding="0"> <tr align="center"> <td width="530"> <table border="0" cellspacing="0" cellpadding="0" width="530"> <tr&g ...

Creating flexible items with a 1:1 ratio and ensuring that the padding on the left and right of the flex container remains consistent

Whenever I adjust the size of the window, the flex-container ends up with uneven padding on the left and right, which is less than ideal. So, I am looking for a way to allow the flex-item to resize when the window size changes, ensuring that the conta ...

Showing an error message without causing any displacement of elements positioned underneath

Is there a way to insert an error message text without displacing the element by 4 units using CSS or Javascript? ...

The MP4 video file is not compatible with the HTML5 video player on Internet Explorer because of encoding issues

I have a website where I used HTML5 to embed a self-hosted video without controls. Initially, the video file was 2mb and it played smoothly on all browsers. However, when I replaced it with a new video file of 16mb, the video stopped playing on Internet Ex ...

How can I line up the bootstrap datepicker with a bootstrap column?

I currently have Bootstrap 3.3.7 and a bootstrap datepicker version 1.6.4 integrated into my project. However, I am facing an issue where the datepicker does not fill up the designated column within a div with the class col-md-6. Here is the HTML code sni ...

Once the "Get Route" button is pressed, I want to save my JavaScript variable into a database

I am seeking to automatically extract data from the Google Maps API and store it in my MySQL database. Specifically, I want details such as source address, destination address, distance, and duration for all available routes to be inserted into my database ...

"Selecting an element through Drag/Drop will result in the element being

INQUIRY I've encountered an issue with a draggable element ($("#draggable")) that interacts with a checkbox ($('#checkable')). When the $('#draggable') is dragged onto a box ($('#droppable')), it checks $(&apos ...

The CSS for the UI Grid is malfunctioning

I have been working on creating a grid using UI Grid (recent version of ngGrid) within my current project. However, I am facing some issues with the display. The icons like angle down and row selected icon are not showing up correctly when I include the CS ...

Validate form for radio group

Hello Experts, I am currently working on developing a form that includes a JavaScript validation function for a radio group. The main objective is to have a division pop up when either "Monday" or "Tuesday" is checked, and no popup when "None" is selected ...