[ListItem] <ListItem component /> require to forwardRef
See original GitHub issuePrior 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:
- Created 3 years ago
- Comments:19 (11 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks. I’ll take a look later what’s wrong with the types. In the meantime, don’t create components during render.
Can I take this if nobody is working on this?