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.

[typescript] Smarter logic?

See original GitHub issue

Problem description

Button has href prop. If that prop is set, a element is used to render the button (https://material-ui-1dab0.firebaseapp.com/api/button/). It would be nice if Button had also target property.

Versions

  • Material-UI: 1.0.0-beta.8

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:30 (24 by maintainers)

github_iconTop GitHub Comments

10reactions
oliviertassinaricommented, Nov 7, 2017

A better alternative where you will not risk a property collision:

<ListItem component={props => <Link {...props} to="/about" />}>
  // ...
</ListItem>

I have always considered the below pattern an elegant “hack” (it’s harder to understand). But what if both ListItem and Link implement a disabled property that you don’t want to share the same value between? You use the pattern above, not below.

<ListItem component={Link} to="/about">
  // ...
</ListItem>

It’s also why you won’t find this third API with Material-UI. It’s a tradeoff between the two previous ones that suffer limitations without being much simpler.

<ListItem component={<Link to="/about" />}>
  // ...
</ListItem>
3reactions
benbayardcommented, Sep 8, 2017

@mctep That looks fine to be, but it should be noted that inline lambdas are highly unperformant. If I were to write docs for this I would write it as:

function buttonLinkCreator(to: string) {
  return (props: ButtonProps) => <Link {...props} to={to} />
}

const HomePageLink = buttonLinkCreator('/');

class Blah extends React.Component {
  render() {
    return <Button component={HomePageLink} />;
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Smarter breadth first search logic? : r/typescript - Reddit
I don't want to overrule TypeScript whenever possible but for a breadth first search logic I had to overrule TypeScript and idk if...
Read more >
The starting point for learning TypeScript
Find TypeScript starter projects: from Angular to React or Node.js and CLIs.
Read more >
[typescript] Smarter logic? #8063 - mui/material-ui - GitHub
Problem description Button has href prop. If that prop is set, a element is used to render the button ...
Read more >
TypeScript Tutorial: A step-by-step guide to learn TypeScript
It is smart enough to figure out types from their values. That way, you won't have to specify your types in your code....
Read more >
13. TypeScript is really smart - YouTube
typescript #tutorials #cse #easylearning #whatistypescriptTypeScript is an open-source programming language advanced and maintained by ...
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