Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: collect the MUI components in single src/ui.tsx #142

Closed
marcinkoziej opened this issue Jan 6, 2022 · 0 comments
Closed

Proposal: collect the MUI components in single src/ui.tsx #142

marcinkoziej opened this issue Jan 6, 2022 · 0 comments
Assignees
Labels
question Further information is requested

Comments

@marcinkoziej
Copy link
Contributor

marcinkoziej commented Jan 6, 2022

My DX painpoint is having to import every @material-ui/core component separately in every file.

  1. It breaks my flow of writing a component, because I have to jump up to top to add an import
  2. It leaves unused imports, if I delete the particular component from the file. I should also remove the import, but it's a chore, and I am incentivized not to do it - i might use that ListItem or Avatar after all in next 10 minutes.

The reason we do it this way is that we believe it will make the bundle smaller. Are we 100% sure it's the case? Is not tree-shaking smart enough to be able to figure out what is used and what not?

I would rather have one:
import mui from '@material-ui'; and use it with prefix: <mui.List>` and so on.

If this would really make the bundle insanely big, my proposal is to create src/ui.tsx which re-exports the most used components. This would actually be an opportunity to standardize the way we use MUI, add styling in central place, maybe create some "flavors" of components that would serve as re-usable pieces of UI we use across dashboard, to not re-invent the wheel every time starting off the stock mui components.

Benefits:

  1. Just one import: import ui from 'src/ui'.
  2. Consistent style in app, we could style some components globally using styled-component pattern, which is recommended for MUIv5

Drawbacks:

  1. <ui.Foo> instead of <ui.Foo> so 3 chars more per tag.

Reading

@marcinkoziej marcinkoziej added the question Further information is requested label Jan 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants