Creating a two-column layout in React with Material-UI to display repeated information

I'm currently developing a component using Grid, and I would like the information to display in two columns instead of just one. I'm having trouble figuring out how to achieve this. I understand that I could potentially add another Grid section with sm={6} to populate two columns, but my data is all coming from a map function, so I don't have additional content to insert into another Grid.

const renderData = (person, picture, index) => {
        return (
            <Paper className={classes.Paper}>
                <img src={person.picture.large} />
            </Paper>
        )
    }
return (
        <div className={classes.sectionContainer}>
            <h3 className={classes.title}>Follow our Instagram!</h3>
            <h3 className={classes.title}>@platformdanceshowcase</h3>
            <Grid container spacing={1}>
                {previewData.slice(0, visible).map(renderData)}
            </Grid>
            <Container className={classes.extendButtonArea}>
                {visible < previewData.length && (
                    <Button className={classes.extendButton} onClick={loadMore}>
                        View More...
                    </Button>
                )}
            </Container>
        </div>
    )
}

Any assistance on this topic would be much appreciated as I've hit a roadblock. Thank you in advance!

Answer №1

As per the documentation, Columns act as components with the item props, replacing the container props used in the Parent.

For example:

<Grid container spacing={1}>
   {previewData.slice(0, visible).map((person, picture, index) => (
      <Grid item key={index}>...</Grid>
   )}
</Grid>

I have not worked with Material UI before, so give it a try!

Source: https://material-ui.com/components/grid/

Answer №2

The Material UI documentation includes this particular code snippet:

<Grid container spacing={{ xs: 2, md: 3 }} columns={{ xs: 4, sm: 8, md: 12 }}>
  {Array.from(Array(6)).map((_, index) => (
    <Grid item xs={2} sm={4} md={4} key={index}>
      <Item>xs=2</Item>
    </Grid>
  ))}
</Grid>

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

Choosing the open status of an HTML list

Is there a way to determine which containers in a list are currently open and which ones are still closed? Currently, I am utilizing the slideDown(), slideDown(), and addClass functions on divs with the specific class="section_hdl_aktiv". However, I want ...

Trying to test a React component using Enzyme? Consider passing your props as events to the

My test is failing because I am unsure of what to include in the onChange attribute value. describe("App", function() { const wrapper = shallow(<App />); it("should contain an input element", function() { expect( wrapper.contains(< ...

Exploring D3.js version 4.10: Leveraging x-axis timescale with Data retrieval using XMLHttpRequest

I'm currently working with D3.js version 4 and encountering two separate issues. Firstly, I have retrieved data using XMLHTTPRequest which includes a name, an identifying number, and additional data. After my ajax request, the structure of the data ap ...

Tips for correcting the `/Date(xxxxxxxxxxxxx)/` formatting issue in asp.net mvc

As a programming novice, I am trying to display data from my database server on the web using a datatable in asp.net mvc. After following a tutorial video on YouTube, I encountered an issue where the date and time columns in my table are displaying as /Dat ...

Struggling to effectively use XPath to target LI elements that contain specific text

Below is the HTML code for the list item in question: <li class="disabled-result" data-option-array-index="1" style="">4" (0)</li> Here is my attempt at using JavaScript to hide this list item, but it's not working as expected: var xpat ...

The ReactJS input box is stubbornly rejecting all input

Struggling with this code and can't seem to figure out why the input lines aren't accepting anything. After searching extensively, I decided it was time to ask for help. P.S. I am new to react class App extends React.Component { state = { inp ...

Struggling to achieve the desired vertical text alignment in a React Native layout

I am in need of assistance with a follow-up question related to my issue. I have a specific layout that I would like to use as a component, but I am struggling to make it more square-shaped using CSS in React Native. Can someone provide guidance on how to ...

Create a 2-column Product Landing page in Magento with a Grid View option

Looking to create a Product landing page with a two-column layout in grid view, limiting rows to 4. Is there a setting in the backend or can I tweak the catalog.xml for this effect? Curious if the pager and sorter can be customized to fit the same style a ...

Issues with Ajax functionality in Laravel version 5.5

Recently, I decided to dive into Laravel 5.5 as a way to explore more advanced frameworks. Having previous experience with Codeigniter and enjoying it, I set out to implement a small CRUD functionality. Everything was working fine until I attempted to inco ...

Is there a way to access an HTML element using Vue's methods?

Here is an example of my Vue component structure: <template> ... </template> <script> export default { methods: { buildDescription () { if (!this.description) { const div = document.createEl ...

Resetting CSS attributes in Kendo UI Mobile when transitioning between views after removing them with jQuery

Dealing with the flicker of unstyled content in my kendo mobile web app has been a challenge, but I found a solution by using a specific CSS rule within my stylesheet: [data-role="content"] { visibility: hidden; } This effectively hides all ...

Using AngularJS to prefill a HTML5 date input field with a default value

Is there a way to bind the default value generated in moment to both the date and time input fields? I have tried using ng-model and directly binding it to the value attributes, but without success. Any suggestions on how to make this work? Edit: Addition ...

Controller function failing to trigger

I'm new to asking questions, so if I've made a mistake, please let me know. I've searched for an answer here but couldn't find one. Any help would be greatly appreciated. I'm attempting to load a list of "Countries" using a contro ...

Issue with Node.js xml2js module: Sitemap attributes are not being recognized during creation

Currently, my project involves utilizing node.js and xml2js to generate an XML sitemap.xml. Everything seems to be in order, but when I try to define attributes like: '$': { 'xmlns': 'http://www.sitemaps.org/schemas/sitemap/0 ...

Leverage ConvexGeometry within the npm release of THREE

Is there a way to utilize ConvexGeometry in the npm version of THREE? It appears that it was introduced in r85: https://github.com/mrdoob/three.js/releases I noticed that it's only present in the example folder. Is there a method to incorporate it ...

c# JavaScriptConverter - understanding the deserialization of custom properties

I'm facing an issue where I have a JSON serialized class that I am trying to deserialize into an object. For example: public class ContentItemViewModel { public string CssClass { get; set; } public MyCustomClass PropertyB { get; set; } } Th ...

Encountering an issue when trying to launch the server in ReactJS

$ yarn start Failed to compile. Cannot read property 'compilation' of undefined error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. error Command failed with signal " ...

Implementing jQuery autocomplete feature using the Rotten Tomatoes API

I am exploring the use of autocomplete to get movie suggestions from Rotten Tomatoes in JSON format. However, the current code I have does not display any suggestions. <script> var apikey = "5xq9w7z2mp7a6cnchkfy52yd"; var baseUrl = "http://api.rotte ...

ExpressJS authentication -> PassportJS: Issue with setting headers after they have been sent

Currently, I am implementing authentication in Express.js using Passport.js. Below is the code snippet from my login.js file: passport.use(new LocalStrategy( function(username, password, done) { //console.log(username); Usercollectio ...

Discover and locate inactive element using Selenium in Python

Struggling with Automation: Unable to Locate Button on Website I'm currently facing a challenge in automating a website as I am unable to locate a specific button using Selenium. The problem lies in the fact that the button is disabled by default, ma ...