question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why are Grid container & item the same component?

See original GitHub issue

As you all know, the grid component consists of two parts - one with the container prop which is the container for grid items with the item prop. My question is, why? It makes the code messier, it makes the docs harder to understand and to read the API methods, and the most important thing is that it’s combining two elements that are separate into one element. That’s like making Card’s CardContent and CardAction into <Card actions>, <Card content> and <Card container>. I don’t see who benefits from Grid being one component with two different behaviours.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:11
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
zachwolfcommented, Mar 16, 2018

This has always made me curious, but your explanation makes sense.

My experience so far tells me that the average use case doesn’t mix container and item props. With that in mind, there could be an easy “best-of-both-worlds” approach. MUI could provide named components that just wrap Grid. Something like:

// src/Grid/Container.js
import React from 'react'
import Grid from './Grid'

export default function Container (props) {
  return (
    <Grid container {...props} />
  )
}

Thoughts? If you think it’s a decent idea, I’d be happy to make the PR. The docs would need to be updated as well in order to add clarification. Maybe that would be a good time to add an example of a layout using both container and item.

0reactions
zachwolfcommented, Mar 19, 2018

Thanks @oliviertassinari! Would it be appropriate to reopen this issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why are Grid container & item the same component? #8013
As you all know, the grid component consists of two parts - one with the container prop which is the container for grid...
Read more >
Understanding CSS Grid: Creating A Grid Container
This initial article will cover what happens when you create a grid container and the various properties that you can use on the...
Read more >
Guide to the MUI grid system - LogRocket Blog
Under the hood, the Grid component uses Flexbox properties for greater flexibility. There are two types of grid components, container and item ....
Read more >
React Grid component - Material UI - MUI
The container and item props are two independent booleans ; they can be combined to allow a Grid component to be both a...
Read more >
Relationship of grid layout to other layout methods - CSS
This is because when you wrap flex items, each new row (or column when working by column) is an independent flex line in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found