Implement ReactJs to generate a series of div elements

In my React component, I am working with a JSON array and generating divs to display key-value pairs. Each object in the JSON contains approximately 60 key-value pairs. In this particular case, I am rendering divs for the 19th index of each object:

import React, { Component } from "react";
import "./Maps.css";
import df3 from "./data/df3.json"
import sample from "./data/sample.json"


class Maps extends Component {
  constructor() {
    super();
    const data = df3;
    this.state = data
  }
  renderDiv = () => {
    var df4 = df3["Devotions"];
    return df4.map(v => {
      return Object.keys(v).map((host) => {
        return (
          <div class={host}>
            {host} {v[host][19]}
            <div class='space' style={{ borderRadius:'19px',
              transform:`scale(${v[host][19]},${v[host][19]})`,
              opacity:'9%'}} >
            </div>
          </div>
        );
      });
    });
  };

  render() {
     return <div id="Maps">{this.renderDiv()}</div>;
  }

}

export default Maps

I want to organize the rendering process so that the divs for each index are displayed sequentially on the screen.

return Object.keys(v).map((host) => {
        return (
          <div class={host}>
            {host} {v[host][19]}
            <div class='space' style={{ borderRadius:'19px',
              transform:`scale(${v[host][19]},${v[host][19]})`,
              opacity:'9%'}} >
            </div>
          </div>

I'm considering wrapping sets of divs that I want to return in a single div and connecting them to a keyframe, but I'm exploring other possibilities for a more elegant solution.

Any assistance or advice would be greatly appreciated!

Answer №1

Here is the solution I believe will work for you:

If you have a collection of objects, where each object contains arrays of data that you need to display sequentially, this code snippet can help achieve that.

renderDiv = () => {
    var df4 = df3["Devotions"];
    let updatedArray = [];
    df4.forEach(v => { 
        Object.keys(v).forEach((hosts) => { 
            updatedArray = [...updatedArray , 
                            ...v[hosts].map((host) => {
                                return (
                                <div className={host}>
                                    {host} {host}
                                    <div className='space' style={{ borderRadius:'19px',
                                    transform:`scale(${host},${host})`,
                                    opacity:'9%'}} >
                                    </div>
                                </div> )
                            })
                            ]
        })
    })
    return updatedArray;
}

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

How to customize a disabled paper-input element in Polymer 1.0?

Help with Polymer 1.0: I've encountered an issue where setting a paper-input element to 'disabled' results in very light gray text and underline, making it hard to read. I've been trying to use CSS to change the text color but haven&ap ...

Tips for automatically closing the Toggle Navigation feature in Vue JS when a user clicks outside of the navigation container

Is there a way to close the toggled navigation menu automatically when the user clicks outside of the navigation container? I have implemented two ul menus inside the navigation menu and would like the subNavActive, safNavAcitve, and repNavUl variables to ...

The CSS box's height should be determined dynamically

Is there a way to create a div with a maximum width of 200px and have the height increase automatically as needed? Can someone assist me with which CSS properties to use? My goal is to keep the width of the box constant while ensuring that any text inside ...

Mastering the art of creating an authentic carbon fiber CSS background

Authentic carbon fiber consists of a series of interconnected grey fibers that resemble woven sheets in grey color. Does anyone have knowledge on how to replicate this pattern using CSS? The examples created by Lea Verou do not accurately depict true carb ...

What is the best way to organize my comments, responses, and replies in an efficient manner?

I am currently working with Nodejs, Express, MySQL, and EJS. In my project, users can create posts and leave comments. They can also reply to comments or replies on those posts. However, I am facing a challenge in sorting the data into objects/arrays for ...

Spree Deluxe - Customizing color scheme variables

We're struggling to modify the color variables in Spree Fancy. The documentation suggests creating a variables_override.css.scss file. But where exactly should this file be placed? We've tried adding it under the stylesheets folder in assets and ...

Developing a trivia game using HTML and JavaScript

I'm in need of some serious assistance with creating a quiz using HTML. My goal is to have a web page where users can visit, take a quiz, and have their responses stored. Unfortunately, I don't have the knowledge or skills required to do this on ...

VSCode is indicating a CSS error, requesting an at-rule or selector

I tried to implement a piece of CSS code I found on a website, but I'm encountering an error in this particular section .pricing-table:hover{ box-shadow: 0px 0px 19px -3px rgba(0,0,0,0.36); /*issue starts from this line*/ .pricing-table__button ...

jQuery ajax issue: Unable to locate file using relative path

I have recently transferred some script from an HTML document to an external file. I updated the jQuery path to point to the new location of the JavaScript file, but now it is unable to locate the necessary PHP file. Can anyone shed light on why this might ...

Error: The JSON response body is not valid at this location. An unexpected token "<" was found in the JSON at position 0

Currently utilizing nextjs and exploring graphql for the first time, attempting to retrieve data from a wordpress site using its graphql endpoint. I have been following the guidelines in this repository: https://github.com/alexander-young/wp-next-headless ...

Placing the jQuery/javascript source pages right before the closing body tag

Multiple plugin instructions recommend placing the javascript/jQuery source right before the closing body tag. I wondered why this advice is given, but couldn't find a clear explanation for it. In my experience, placing the src file anywhere in the s ...

Unable to access the Vuex state within a Vue component

Upon logging in, I am attempting to retrieve user data. However, instead of an array of users, it is returning an Object. Code Main component (App.js) <script> export default { data() { return { user: ' ...

Implementing a delayed defaultValue in React Select using React Hook Form

Utilizing react-select dropdown with the react-hook-form library, I encountered an issue where the defaultValue from an API call was not prepopulating the dropdown. To work around this, I had to re-render the entire JSX when receiving data from the API. &l ...

Using JavaScript to filter through a nested array of objects

I'm having trouble filtering a nested array of objects. Could someone please point out where I might be making a mistake? Here is the data, and I want to filter out all objects that have a risk of P1 { "title": "QA", ...

Jest is having trouble recognizing a custom global function during testing, even though it functions properly outside of testing

In my Express app, I have a custom function called foo that is globally scoped. However, when running Jest test scripts, the function is being recognized as undefined, causing any tests that rely on it to fail. This is declared in index.d.ts: declare glob ...

Error: JSON input ended unexpectedly, and data retrieval is not possible

Encountering the following error message: SyntaxError: Unexpected end of JSON input https://i.stack.imgur.com/ivG2e.png Modifying the code causes the page to endlessly load without stopping Utilizing Next.js for development The API directory being used ...

What is the best way to blur the background image without impacting the content displayed on top?

Is there a way to blur the background image without affecting the content above it? I'm having trouble achieving this as blurring the parent element also blurs the content. Any suggestions on how to fix this issue? I've tried a few steps but none ...

Preventing the occurrence of [ { "description": null } ] in PostgreSQL with a React application running on http://localhost:3000

While working on my localhost project at port 3000 in the Pern Todo List, I encountered a bug. When I type something and click "Add" using a POST request from my React app, the data should be added successfully. However, when I use Postman to make a GET re ...

Tips on resizing the infoWindow in Google Map

I am having trouble with my infoWindow on Google Maps displaying the correct information. I need to adjust the size of the white div to match the grey box inside and also resize the arrow that connects the marker to the white div. Check out the image belo ...

Apologies, but visual content is unavailable at this location - Google Satellite Map viewing is not

Recently, a strange issue has occurred while using the Google Satellite map on our application. Everything was working smoothly until the map images suddenly stopped showing up. Instead of the terrain images, we are now faced with a message that says "Sorr ...