Utilizing ReactJS to Display Data in Double Columns

I have a Component that looks like this:

export const RenderDetail = props => {
  const createRows = props.content.reduce(function (rows, key, index) {
    console.log('rows, key, index', rows, key, index);
    return (index % 2 === 0 ? rows.push([key]) : rows[rows.length - 1].push(key)) && rows;
  }, []);

 return (
    <div>
      {createRows.map((row, index) => {
        return (
          <div key={`item_${index}`}>
            <Row>
              {row.map((col, key) => {
                return (
                  console.log('col ', col),
                  (
                    <div key={`item_${key}`} style={{ margin: '20px' }}>
                      <Col>
                        <dl className="jh-entity-details">
                          <dt>
                            <span id={col.id}>{col.name}</span>
                          </dt>
                          <dd>{col.value}</dd>
                        </dl>
                      </Col>
                    </div>
                  )
                );
              })}
            </Row>
          </div>
        );
      })}
    </div>
  );
};

When passing an array of objects to this component like:

const Container = [
{
 id: "id",
 name: "ID",
 value: "10"
},
]

The desired outcome would be:

I am looking to display the data in two columns across the page. Currently, they appear too close and tightly packed together. Is there a way to format them so they fill out the whole page while still being displayed in two columns?

EDIT:

By using <Col xs="12" md="6"> as suggested.

https://i.sstatic.net/Dxeoo.png

Answer №1

I made changes to your sandbox. Please check out the updated version.

The issue was with this section of the code.

                <div key={`item_${key}`} style={{ margin: '20px' }}>
                  <Col>

sandbox

To fix it, I removed the enclosing div around the Col tag and adjusted the 6-grid attribute to be 50% width.

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

Ways to update the state property value in the nested child component

Having trouble understanding how to update a specific property within this.state of a parent component, from a child component that is nested inside another child component. I understand the concept of passing a function to a child component and having it ...

Exploring the power of React Hooks with the useState() function and an array filled

When creating new "Todo" items and modifying the fields, everything works fine. However, my problem arises when trying to retrieve the child data after clicking the "show all objects" button. To better understand my issue, here is a code example: const Co ...

Angular 2 orderByPipe not displaying any results initially

At first, I thought the reason for not displaying anything initially was due to it not being async and returning an empty array. Everything worked fine without the pipe, but the posts weren't shown on startup. After submitting a post, all the posts ap ...

Automatically adjust column sizes using Bootstrap's responsive width feature

While I have a feeling this question might have been asked before, my search has turned up no similar issues. I am currently working on styling a menu bar using a standard bootstrap row and columns setup (flexbox). The menu is dynamically generated by Wor ...

Emulating Data in Angular 2 Using Configuration Similar to Ember Mirage

Is there a way to mock data through configuration in Angular 2 similar to how it's done in Ember Mirage? I'm aware that I can create my own solution using Dependency Injection and MockBackend to intercept HTTP calls and provide dummy data. Howeve ...

using jQuery to eliminate an HTML element based on its attribute

How can I remove an element with the attribute cursor = "pointer"? I want to achieve this using JavaScript in HTML. Specifically, I am looking to remove the following item: <g cursor="pointer"></g>. It's unclear to me why this element has ...

Collapse the borders of Angular's div layout container

I need help with collapsing the borders of div containers when generating a table using angular material's layout system. To see what I have done so far, please refer to my jsfiddle linked below: Jsfiddle Below is the HTML code snippet. Any guidance ...

There appears to be an unspecified parameter in the controller related to the ng

After fetching data from an API, I use it to populate a form with cascading select fields. I have two functions in place to filter the array based on the selected options, but I am running into an issue where I cannot access properties from ng-model. For ...

Testing React Hooks useEffect and useCallBack can be done by writing unit tests that check

I've been working on writing unit test cases using Jest and Enzyme for React hooks like useEffect and useCallback. However, I'm facing challenges in successfully testing my code. Can someone provide assistance in creating a test case for the code ...

I am struggling to comprehend the code for a PHP form that triggers a JS OnUpdate event, which then uses AJAX to retrieve data from MySQLi

I want to give a special thanks to Alon Alexander for providing the JS and AJAX code, even though I don't fully comprehend it. I am more comfortable using PHP/JS without jQuery, but I am struggling to make it function as intended. My current issue in ...

Can wildcard paths be imported in React using Typescript?

Is there a way to dynamically import a React Typescript Component from a wildcard path, similar to the following code snippet? const Component = loadable( () => import(`../../../src/**/*/${component_name}`), ); I have searched numerous solutions on ...

Ways to display or conceal a component based on the current component being used

I am a newcomer in Angular, and I believe finding the solution to my problem will be a great learning experience. In my default component, the MainComponent is loaded in my <router-outlet>. At this stage, both the menu and the footer are displayed. H ...

Are there any missing (or "optional") expressions in handlebars.js?

Currently, I am developing a build script using Node.js. To summarize, the script carries out the following tasks: Prompting the user for essential information such as the project name and description Cloning a template from a Git repository Renaming fil ...

Adding a method to a node module by hand

Working with my website, I've incorporated the material-ui package, but the version available on npm is outdated compared to the latest one on Github. To reflect these updates, I manually inserted this line of code into their Theme Manager class: set ...

Cross-origin request, specifying Content-Type as application/json

I'm currently developing a web application with a React front end and a node back end. Both are running locally on my computer, at localhost:3000 for the front end and localhost:8080 for the back end. I'm trying to make a CORS request using heade ...

"Exploring the dynamic manipulation of CSS display property through the use of an active class

When attempting to implement a small pop-up window for user confirmation before navigating away from the page, I encountered an issue. Upon clicking the RUN button with the id "openBtn," the pop-up window briefly appears and then disappears. I'm unsur ...

Using Jquery to select and apply functions to specified div elements

As someone who is relatively new to JQuery, I have a question regarding the .on() function. Take this example: $('div').on('click', function() {$(this).toggleClass('show-description');}); This code selects all the 'div& ...

Validating an object's schema using AJV when there are unknown properties present

Within my platform, there is an amusing scenario that I find to be the most effective. I am currently attempting to validate a JSON Schema where an object contains unknown keys with a consistent schema as their values. Each key represents a unique ID and h ...

"Material-UI enhanced React date picker for a modern and user-friendly

Currently, I am utilizing the Date picker feature from Material UI. The code snippet responsible for implementing it is as follows: import { DatePicker } from 'redux-form-material-ui'; <Field name="birthDate" ...

Adding link styles to the <a> tag in Bootstrap 4 Alpha 3: A simple guide

The following code is quite simple: <a>This is a link</a> In a demonstration of Bootstrap 4 Alpha 2 here, the link appears blue. When you hover over it, it turns dark blue. However, in a demonstration of Bootstrap 4 Alpha 3 here, it displays ...