Exploring the CSS Cube Effect within a React Environment

I am currently attempting to replicate a cube within a webpage I am constructing using react (I am relatively new to react, so please bear with me if this is a novice question)

Link to Cube Visualization

Creating a component that contains the HTML structure for the cube.

class Cube extends Component {
  render() {
    return (
      <div className="cube">
        <div id="wrapper">
  <div class="viewport">
    <div class="cube">
      <div class="side">
        <div class="cube-image">1</div>
      </div>
      <div class="side">
        <div class="cube-image">2</div>
      </div>
      <div class="side">
        <div class="cube-image">3</div>
      </div>
      <div class="side">
        <div class="cube-image">4</div>
      </div>
      <div class="side">
        <div class="cube-image">5</div>
      </div>
      <div class="side">
        <div class="cube-image active">6</div>
      </div>
    </div>
  </div>
</div>
      </div>
    );
  }
}

Added the CSS from the provided website into a separate file and imported it:

import './ProductPage.css';

(see link above for css. The CSS is just copy pasted).

Successfully rendered the cube using another component:

class NewProductPage extends Component {

  constructor(props) {
    super(props);
    this.state = {
      img: null,
    };
    this.onDrop = this.onDrop.bind(this);
  }
  onDrop(acceptedFiles){
    this.setState({
      img: acceptedFiles[0].preview,
    })
  }
  render(){
    return (
      <div>
        <Cube />
        <div className="DropPicBox">
          <DropZone onDrop={this.onDrop}>
            {this.state.img ? 
              <div>
                <img className="PicBox" src={this.state.img} />
              </div> 
              : null}
          </DropZone>
        </div>
        </div>
    );
  }
}

The rendering seems to be incorrect as seen here:

https://i.sstatic.net/dFvTM.jpg

My query pertains to the behavior of react when applying CSS that may alter the appearance of the cube. To exemplify, I used jsfiddle to model a similar cube using HTML and CSS obtained from this site: JSFiddle Cube Example

The rendition of the cube appeared accurately in the JSFiddle example:

JSFiddle Rendering

Answer №1

When working with JSX, it is important to remember that the correct attribute to specify a class for an element is className, not class. For example:

<div className="foo">...</div>

instead of

<div class="foo">...</div>

You may have used the correct syntax in some instances, but your first codeblock (Cube) contains several instances where class is used instead of className.

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

Generate an electron atom application using hardware data

I'm in the process of creating a desktop application. Given my experience with using JavaScript for mobile HTML5 apps, I've been considering using Electron Atom (formerly known as Atom Shell) to develop this desktop application. However, my clie ...

What is the best way to expand ScrollToBottom to cover the entire screen height?

Check out this code sandbox that showcases a Logs React component functioning perfectly. The implementation incorporates react-scroll-to-bottom to display a page with a header and logs. What's interesting is that the log section dynamically adjusts i ...

AngularJS: Error - Undefined value instead of a function argument

Recently, I decided to dive into learning AngularJs and took my first steps by setting up a view, service file, and controller file separately. Below is an outline of how I went about it: <html ng-app="myApp"> <head> <script src="https://aj ...

Is it the right approach to configure Sentry on Gatsby after creating a project on react?

I am using Sentry to track crashing reports, and I have set up my project with React on Gatsby. I have added the plugin correctly in the gatsby.js file, but when I create an issue in one of the components, it does not reflect in the Sentry issues. I cannot ...

Bootstrap 4 - Ensuring Tables are Mobile Responsive and Precisely Sized for Desktop viewing

Allowing users to customize table column widths in percentages that total up to 100 provides flexibility. However, this results in cramped tables on mobile devices. To address this issue, I aim for the table to become horizontally scrollable with the boo ...

Combining Angular with Node.js: Uncaught TypeError - error.json() is undefined

I've been diving into a course on integrating node.js with Angular and I'm following the tutorial step by step. However, I encountered an error that has me stuck. Is there anyone who can provide some guidance? The error I'm facing is: Ty ...

Is there a way to eliminate the quotes from the JavaScript output?

I've gathered data in the following format: [ 0: {latitude: "0", longitude: "0", user_country_name: "-", user_country_code: "-", total_visitors: 4} 1: {latitude: "-33.867851", longitude: "151.20 ...

Angular template driven forms fail to bind to model data

In an attempt to connect the model in angular template-driven forms, I have created a model class and utilized it to fill the input field. HTML: <div class="form-group col-md-2 col-12" [class.text-danger]="nameCode.invalid && nameCode.touched ...

What is the best way to obtain the id of an HTML element that is generated within jQuery code?

Typically, data is retrieved in HTML by storing the html in the html file. In my case, however, I create the html element inside jQuery. So, how do I call out the div id? How can I replace document.getElementByID ("edit").innerHTML=.... when the element i ...

Leverage the power of Shopify API to retrieve a list of all products by making a request through

My website is custom built on node.js, and I am looking to retrieve all of my products in a single GET request. Unfortunately, the Shopify buy-button feature does not allow me to display all products at once due to pagination, hindering my ability to effec ...

Running webpack to compile a TypeScript project

Here's a question for you - is there a way to achieve multi-file compilation while maintaining the folder and file structure, without explicitly specifying each file in the entry configuration like this? entry: { index:'./src/index.ts', ...

Change the alert notification to a pop-up window

Is there a way to show a pop-up message instead of an alert when a user clicks on a specific product set? Here is the current code I have: <script> $(document).ready(function(){ $('.pre-sale-product').on('click&apo ...

Comparing hardware-accelerated CSS3 animations, transitions, and jQuery animate for mobile devices

While developing my app using PhoneGap and jQuery, I encountered a dilemma regarding animations. Initially, I relied on what I knew best - jQuery animate - to create smooth movements. However, discussions about hardware acceleration caught my attention. ...

Limit the usage of Lightning Web Component instances to only one per user

Is there a way to restrict users in Salesforce to using only one instance of a Lightning Web Component? I am new to Salesforce Lightning Web Components and looking for a solution to limit the number of instances a user can create through either permission ...

Having trouble with the Split-form Stripe payment method? Card information such as the number, expiry date, and CVC number isn't coming through?

Currently, I am working on integrating Stripe with React and Node. However, I am facing issues retrieving certain values. <CardNumberElement/> <CardExpiryElement/> <CardCvcElement/> Without these values, I am unable to gene ...

"Implementing a spinning wheel feature using HTML and JavaScript to dynamically add components

Trying to add a needle on top as a stopper. Previously, a custom-created SVG arrow was used, but now attempting to replace it with a needle.png at the same position. Any suggestions? Various options were tried to add an image in JS, but none of them work ...

Browsing across pages seamlessly without the need to refresh the browser

I need help with making my admin panel built using Bootstrap and integrated with Laravel navigate through tabs without refreshing the browser. Can anyone provide guidance on how to modify the code to achieve this functionality? You can check out the admin ...

How to use AngularJS to showcase intricate data structures

Here is the JSON data that I have: { "_id": "543e95d78a1cec2a38ed53ec", "result": { "CAR009": [ { "name": "BMW" }, { "name": "MERCEDES" } ], "BUS007": [ { ...

Double firing issue with AJAX Product Filtering upon button click

I am in the process of creating a WordPress online store using an Ajax Filtering Plugin that allows users to filter products by category and other criteria. However, I have noticed that when I click on a category button, the URL is being requested twice, ...