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.

[ListItem] <ListItem component /> require to forwardRef

See original GitHub issue

Prior to upgrading to the 5.x alpha, the following code from the docs worked:

const link = (p: unknown) => <Link to={route} {...p} />;
<ListItem button key={route} component={link}>
  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

I also looked at the release notes and the specs provided in the source code, but can’t seem to find anything.

Current Behavior 😯

Throws a runtime error:

Warning: Failed prop type: Invalid prop `component` supplied to `ForwardRef(ButtonBase)`. Expected an element type that can hold a ref. Did you accidentally provide a plain function component instead?

And:

Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?

The component does render correctly, though.

Expected Behavior 🤔

No runtime errors 😉

Your Environment 🌎

Tech Version
Material-UI v5.0.0-alpha16
React 17.0.0
Browser Chrome
TypeScript Yes (4x)
etc.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:19 (11 by maintainers)

github_iconTop GitHub Comments

3reactions
eps1loncommented, Nov 20, 2020

Thanks. I’ll take a look later what’s wrong with the types. In the meantime, don’t create components during render.

2reactions
huzaimacommented, Dec 31, 2020

Can I take this if nobody is working on this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

[ListItem] <ListItem component /> require to forwardRef #23622
The issue is present in the latest release. I have searched the issues of this repository and believe that this is not a...
Read more >
ForwardRef error in ListItem component when using NavLink
ListItem tries to specify a ref on the component you specify via the component prop. Refs are not supported by function components except...
Read more >
Forwarding Refs - React
Ref forwarding is an opt-in feature that lets some components take a ref they receive, and pass it further down (in other words,...
Read more >
Composition - Material UI - MUI
The component receiving the component prop (e.g. ListItem) might intercept the prop (e.g. to) that is destined to the leave element (e.g. Link)....
Read more >
UseRef, CreateRef, ForwardRef? What's up with refs in React?
So let's useforwardRef! If you wrap forwardRef around the component that you want to reference, you can pass in a ref as an...
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