Moving Material-UI Grid column overflow to the following row

I'm working on displaying a list of items in a specific format using Material-UI Grid. The desired layout is:

item1 item2

item3 item4

item5 item6

Currently, my code generates the items in a single column like this:


const display = () => {
  return(
    <React.Fragment>
      {items.map(i => (
        <Grid item xs={3} direction={'row'}>
          {i}
        </Grid>
      ))}
    </React.Fragment>
  )
}

return (
          <Grid item xs={4} alignItems={"flex-start"}>
            items:
          </Grid>
          <Grid item xs={8} justify={"center"} alignItems={"flex-end"} direction={"column"}>
            {display()}
          </Grid>
)

Answer №1

To ensure an even distribution of items, utilize the Grid system which is structured on 12 points. Keeping xs={6} will achieve this effect.

<Grid container>
  {items.map((item, key) => (
     <Grid item key={key} xs={6} className={classes.item}>
         {item}
     </Grid>
   ))}
</Grid>

If you require a demonstration, visit https://codesandbox.io/s/material-demo-qe7mr. I hope this information proves beneficial to you. Thank you.

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

What steps can I take to resolve the issue of text/data overflow within material-ui?

Having an issue with data overflow in my MaterialTable from material-ui when viewed on mobile devices. It displays fine on desktop, but the table data spills over on smaller screens. How can I resolve this problem? <MaterialTable className={clas ...

Having trouble aligning text and images in React with Material-UI?

I am currently working on designing my portfolio website using reactJs and material-ui. I am facing an issue with aligning the image with text and also a problem with non-responsive text. Essentially, I am trying to achieve text on the left side and image ...

Menu icon in Next.js/React/Tailwind not triggering close action when clicked again, causing responsiveness issue

Hey there, I'm relatively new to working with Next.js and React. Right now, I'm tackling the challenge of creating a responsive navbar that toggles open and closed when clicking on the hamburger icon (and should also close when clicked outside th ...

Heroku deployment unable to refresh node modules after git push

Can someone assist me with a problem I'm encountering while trying to deploy my project on Heroku? The issue revolves around my utilization of "react-animations" and the customization I've applied to a particular animation within the library. Ess ...

Animating the change in Slider value with Material-UI in React

Recently delving into React, I encountered my first challenge that has been consuming my time for hours. I'm working with a Slider component from Material-UI and seeking to animate the value changes. Currently, when clicking on a button, the slider i ...

How can you initialize the app in Next.js regardless of the routes being entered?

Within my application, I am facing the challenge of loading global data into the Redux store at the start of the app. Initially, I utilized a useEffect with a run-once functionality on the homepage with the route /. As I introduce new routes, such as /use ...

The Reactjs infinite scroll feature continuously displays fresh data

Every time I scroll, my data is always rendering on page 2 and page 1 disappears, and the items.concat function is not working properly. My fetch data code looks like this: const FetchUrl = async (p) =>{ const Url = await fetch(`api-link=${p}`); ...

Printing a React component using a button causes formatting related to className to be lost, while printing it inline preserves the formatting

I've hit a roadblock in trying to figure out the React and printing issue for the past week and a half, and it feels like I'm going in circles. Despite finding some helpful solutions on Stack Overflow, none of them seem to work completely for me ...

Uh oh! It appears that the Nextjs stripe-webhook api endpoint is missing. Error

Recently, I have been encountering a [404] POST http://localhost:3000/api/stripe-webhook error while listening on stripe. I am currently running the NextJs version "14.1.3". The stripe-webhook.ts file is located at 'app/api/stripe-webhook.t ...

Encountering an NPM error while trying to install particle.js within a React

Encountering this error while attempting to install particle.js on my React App: Error ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfe ...

Passing an array of objects as properties in React components

My functional component looks like this: function ItemList({ items }: ItemProps[]) { return <p>items[0].name</p> } Here is how I'm creating it: <ItemList items={items} /> The array items contains objects in the format [{name: &ap ...

An issue occurred during the hydration process, causing the entire root to switch to client rendering since the error occurred outside of a Suspense boundary

I've started seeing some errors and warnings: Error: An error occurred while hydrating. Since it happened outside of a Suspense boundary, the entire root will switch to client rendering. Error: Hydration failed due to initial UI not matching what was ...

Encountering an error message saying "assignment to undeclared variable"

I'm attempting to incorporate a react icon picker from material-ui-icon-picker However, I keep encountering an error stating "assignment to undeclared variable showPickedIcon" edit( { attributes, className, focus, setAttributes, setFocus, setState ...

Is there a way to customize the text color beneath a Doughnut chart using react-chartjs-2?

Currently, I am utilizing the Doughnut feature from the react-chartjs-2 library and I have a specific request. My goal is to change the color of the text beneath the graph to white because it is difficult to read against the current background (please refe ...

Changes to the state will not be reflected until a poll is conducted

Here we have an example of state being initialized and passed down to a child component: const [rowCount, setRowCount] = React.useState<number>(1); <Foo setRowCount={setRowCount} /> Foo: const Foo = (props) => { const { setRowCount } ...

How can I display a minimal number of rows in a Multiline TextField in Material UI with ReactJS without any scrolling beyond that limit?

When using Material UI Texfield for multiline input, I am looking to display a minimum of 3 rows initially and then have the text area expand further without showing a scroll bar if the content exceeds 3 rows. I attempted the following: <TextFi ...

Receiving an error while passing properties to a React component: "Property 'firstName' is not found on type 'Readonly<{}>'."

As a beginner in React, I need some patience I'm attempting to create a simple component where users can input their first and last names, update the values, and see them displayed after clicking a button. However, I keep encountering TypeScript comp ...

Issue with MaterialUI and ReactJS: MobileDatePicker does not close after selecting a date

After implementing closeOnSelect for selecting a date, I am encountering an issue where the date picker remains open even after selection. The only way to make it disappear is by either escaping or clicking the OK or Cancel buttons. This issue occurs on bo ...

What are the steps for distributing a styled React component?

My goal is to release a UI library using React, but I am struggling with how to handle styles. When I write code in a project, I typically use webpack and babel to build my code, resulting in the creation of a *.css file. import React from 'react&ap ...

Nodemailer contact form malfunctioning

I've been working on setting up a contact form in React and utilizing nodemailer to send messages to my email, but I seem to be encountering some issues. I have a server.js file located in the main folder along with Mailer.js which contains the form c ...