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

ButtonBase didn't accept function as component property #15823

Closed
andryxaSc opened this issue May 24, 2019 · 7 comments
Closed

ButtonBase didn't accept function as component property #15823

andryxaSc opened this issue May 24, 2019 · 7 comments
Labels
support: question Community support but can be turned into an improvement

Comments

@andryxaSc
Copy link

In upgrading material v3.9.3 to v4.0.0 error happens. The error happens only in v4.0.0.
I am trying to pass NavLink component to Tab.

ButtonBase.js:142 Uncaught (in promise) Error: Material-UI: expected an Element but found null. Please check your console for additional warnings and try fixing those. If the error persists please file an issue.

Wrapping NavLink with class component resolve this issue.

@eps1lon
Copy link
Member

eps1lon commented May 24, 2019

Please check your console. There should be multiple warnings. One of which links to https://material-ui.com/guides/composition/#caveat-with-refs

@eps1lon eps1lon added component: button This is the name of the generic UI component, not the React module! working as intended labels May 24, 2019
@oliviertassinari oliviertassinari added duplicate This issue or pull request already exists and removed component: button This is the name of the generic UI component, not the React module! working as intended labels May 24, 2019
@oliviertassinari
Copy link
Member

oliviertassinari commented May 24, 2019

I'm closing as a duplicate of #15827 as it follows the issue template.

@oliviertassinari oliviertassinari added component: ButtonBase The React component. working as intended and removed duplicate This issue or pull request already exists labels May 24, 2019
@hsimah
Copy link
Contributor

hsimah commented May 27, 2019

EDIT tl;dr NavLink expects the prop innerRef not just ref.

I'm currently upgrading to v4 and this issue has presented itself. If I use a React Router Link my components render correctly, if I use a NavLink I get the ref caveat error.

// works
<Tab
    label='Profile'
    icon={<Star />}
    value={`${url}/profile`}
    component={Link}
    to={joinPath(url, 'profile')}
    classes={{
        root: classes.tab,
    }}
/>
// also works, but ugly
<Tab
    label='Profile'
    icon={<Star />}
    value={`${url}/profile`}
    component={React.forwardRef((props, ref) => <NavLink {...props} ref={ref}/>)}
    to={joinPath(url, 'profile')}
    classes={{
        root: classes.tab,
    }}
/>

@hsimah
Copy link
Contributor

hsimah commented May 27, 2019

@eps1lon thanks, the ref prop on a NavLink is called innerRef not ref. Supplying the forwardRef wrapper and the correct prop name works.

@eps1lon
Copy link
Member

eps1lon commented May 27, 2019

@eps1lon thanks, the ref prop on a NavLink is called innerRef not ref.

Not sure what you're referring to. The documented fix doesn't use ref but innerRef for that exact reason. A future react-router version wouldn't need innerRef anymore.

@hsimah
Copy link
Contributor

hsimah commented May 27, 2019

Not sure what you're referring to. The documented fix doesn't use ref but innerRef for that exact reason. A future react-router version wouldn't need innerRef anymore.

My code sample - I was using the incorrect prop name. All good, code working now.

@oliviertassinari oliviertassinari added support: question Community support but can be turned into an improvement and removed component: ButtonBase The React component. waiting for user information labels Oct 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support: question Community support but can be turned into an improvement
Projects
None yet
Development

No branches or pull requests

4 participants