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.

Make GridItem into a prop on Grid instead of a separate component

See original GitHub issue

It’d be easier to use Grid if we didn’t need to import 2 components, and could instead use pass a prop <Grid item>. Coming from MaterialUI it is easier to consume this way. Also, it’s more legible since the syntax highlighting is more contrasting with the Grid tag surrounding it.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
fandycommented, Dec 7, 2020

@with-heart, those are some great reasons. It’s not a huge annoyance to import them separately, and I can quickly see myself getting used to it. The pros you listed also make it sound like a more flexible solution in the long term.

I come from MaterialUI and notice the difference in API design in ChakraUI. For example, I like that the library is minimal and doesn’t include AppBar, instead opting for recipes (although documentation on those can be improved).

1reaction
with-heartcommented, Dec 7, 2020

I understand that importing multiple components rather than baking all functionality for each “module” into a single component is a stylistic choice we’ve made, but we feel that it pays off in terms of the amount of flexibility and extensibility it gives in how end users can utilize these components. On top of that, an api that relies on which prop is passed to a component to determine the functionality of that component has a number of technical hurdles (the big one that comes to mind is correct types), none of which are impossible to overcome but lead to imo particularly dirty component implementations.

imo an api like this would lead to semantic confusion. In your above example, you’re rendering a Grid component which at a glance would suggest enables display: grid, but the item prop means that it’s not actually a grid. So why call it a grid?

The last thing that comes to mind which is related to the above comment about extensibility is that we allow users to create/extend components using the chakra factory function, which this change would make less flexible:

// How do we tell this we actually want to extend grid-as-item and not grid-as-grid?
const CoolGridItem = chakra(Grid, { baseStyle: { bg: 'red.900', color: 'white' }})

I definitely hear your concern here and can tell you that I’ve heard similar feedback from co-workers around Modal, but it seems to have been a temporary discomfort and after using it a few times, it becomes second nature of which components to import to build a modal.

Especially after having already established this as the Chakra api style for the past year+, this is just not a realistic request for us to consider. I hope you understand and will still consider using Chakra! We believe the flexibility and extensibility of the multi-component api is worth the trade-off in convenience.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Guide to the MUI grid system - LogRocket Blog
You can apply the spacing prop to the Grid container to create spaces between each individual grid item . In the following example, ......
Read more >
Using a Link as a Material UI Grid item's component prop
According to the Material UI documentation, you can supply either a string or a component to the component property of a Grid item....
Read more >
Using the Grid Component in Material-UI to Create ...
In this article, we will learn about how to use the Grid component in Material-UI to create a responsive layout for a React...
Read more >
React Grid component - Material UI - MUI
The Material Design responsive layout grid adapts to screen size and orientation, ensuring consistency across layouts.
Read more >
Grid - Chakra UI
Here's an example of using grid template columns with the grid component, ... Pass the colStart and colEnd prop to GridItem component to...
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