Material-ui: ButtonBase didn't accept function as component property

Created on 24 May 2019  路  7Comments  路  Source: mui-org/material-ui

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.

question

All 7 comments

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

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

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,
    }}
/>

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

@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.

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chris-hinds picture chris-hinds  路  3Comments

mattmiddlesworth picture mattmiddlesworth  路  3Comments

pola88 picture pola88  路  3Comments

ryanflorence picture ryanflorence  路  3Comments

FranBran picture FranBran  路  3Comments