-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
Component Render API? #10124
Comments
@christophediprima A live reproduction example would have been great. I do think I know the origin of what you are describing. I have already experienced it. If you create a new component in the render lifecycle, it will get unmounted during the next render. You need to move the component creation outside. I want to look into a component render API in the future to prevent this issue. |
Ran into this last week, I assume this is the same issue @christophediprima has. Although, I am not sure if this really is MUI's fault. It's just doing you what you tell it to do. Passing an inline function to the To "fix" this change your component to do the following: class ListItemLink extends React.Component {
renderLink = (itemProps) => (
<Link to={this.props.to} {...itemProps} />
);
render() {
const{ icon, primary, secondary, to } = this.props;
return (
<li>
<ListItem button component={this.renderLink}>
{icon && <ListItemIcon>{icon}</ListItemIcon>}
<ListItemText inset primary={primary} secondary={secondary} />
</ListItem>
</li>
);
}
} Sandbox: https://codesandbox.io/s/6l40v1nvqr |
If people run into the above, I suggest updating the documentation -> https://material-ui.com/demos/buttons/#third-party-routing-library |
@sebald I agree. Do you want to take care of it? :) |
Thanks guys! You are too kind! Sorry about this... I was on a hurry and I just wanted to ping if someone had the same issue... Shame on me! |
@oliviertassinari Will do! ... feeling bad for not contributing to MUI anymore anyway 😇 |
@oliviertassinari I wonder where to put this information. Since re-rendering will always happen if people use an inline function for the Side note: I stumbled upon this when I wrote a wrapper/an abstraction that enforced some usage constraints on MUI components. I basically was "composing" MUI components :D |
@sebald I was thinking of updating the demo with something like: import { Link } from 'react-router-dom'
import Button from 'material-ui/Button';
+const MyLink = props => <Link to="/open-collective" {...props} />
-<Button component={props => <Link to="/open-collective" {...props} />}>
+<Button component={MyLink}>
Link
</Button>
Yeah, I haven't thought about this one. It's a great idea 👍 . |
@sebald has documented the limitations of the |
When using a third party Link component in a button. The animation that should cover the entire button is interrupted because of the re-rendering of the custom Link component.
The text was updated successfully, but these errors were encountered: