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

[Grid] Generify props with component property #16590

Merged
merged 3 commits into from
Jul 14, 2019

Conversation

JipingWang
Copy link
Contributor

@JipingWang JipingWang commented Jul 12, 2019

fix TypeScript check error.

  • Property does not exist on Grid: 'elevation'
  • Property does not exist on Grid: 'square'

fix TypeScript check error.
@mui-pr-bot
Copy link

mui-pr-bot commented Jul 12, 2019

No bundle size changes comparing f3383e8...d7cc424

Generated by 🚫 dangerJS against d7cc424

@mbrookes mbrookes added the docs Improvements or additions to the documentation label Jul 12, 2019
@oliviertassinari oliviertassinari added component: Grid The React component. typescript and removed docs Improvements or additions to the documentation labels Jul 12, 2019
@oliviertassinari oliviertassinari changed the title Update SignInSide.js [Grid] Generify props with component property Jul 12, 2019
Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed the approach to fix the underlying TypeScript definitions. It replicates what @ypresto started in #16487 to this, not yet handled, component.

@oliviertassinari
Copy link
Member

@JipingWang Thanks for reporting the issue!

@@ -61,7 +61,7 @@ export default function SignInSide() {
<Grid container component="main" className={classes.root}>
<CssBaseline />
<Grid item xs={false} sm={4} md={7} className={classes.image} />
<Grid item xs={12} sm={8} md={5} component={() => <Paper square elevation={6} />}>
<Grid item xs={12} sm={8} md={5} component={Paper} elevation={6} square>
Copy link
Member

@eps1lon eps1lon Jul 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a random thought but would it maybe make more sense to push towards something like

function GridPaper() {
  // but something specific here e.g. const className = useGrid(); or const css = useGrid()
  const props = useGrid({ item, xs: 12 });

  return <Paper {...props} />
}

The current approach tends to grow quite nasty (member hocs?) with regards to what props belongs to what e.g. <Grid item elevation={12] component={Paper} /> (is elevation a Paper or Grid prop?).

IMO components should only ever accept strings for host components. There are a few exceptions like Links but I'd hope these will be replace with hooks in the future.

Copy link
Member

@oliviertassinari oliviertassinari Jul 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some thought:

  • useGrid requires a hook ready CSS-in-JS solution.
  • This example doesn't need to use the component prop. We could refactor it. (+1 dom node)
  • This example is lazy, it could create an intermediary component.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'm not really sure about the best API. IMO this <Render component={Something} /> pattern is just disguised hoc. I might've been a good idea for router links but I think it got abused1 beyond that.

1 At least now we might be able to provide a better API with hooks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: Grid The React component. typescript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants