Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
[ListItem] <ListItem component /> require to forwardRef #23622
Comments
|
Why is the new warning wrong? |
|
@oliviertassinari I make no claims about the "warning being wrong," but obviously it broke my app when I migrated to v5 If this is an intended syntax change, I am looking for documentation on the migration solution. As I said in the OP, I have examined the release notes and the specs (in the source code) and do not see an obvious migration path. |
|
FWIW, I've also tried using |
Could you share that particular code? It should work. |
|
Sure thing. I relied on the IDE to complete the
Exact error is:
|
|
Thanks. I'll take a look later what's wrong with the types. In the meantime, don't create components during render. |
|
@eps1lon copying the code exactly from the example in the link, I first get:
note: Typescript required that I add the Removing the
|
|
@zaneclaes So If I summarize:
import * as React from "react";
import ListItem from "@material-ui/core/ListItem";
import { MemoryRouter } from "react-router";
import { Link, LinkProps } from "react-router-dom";
export default function ListItemLink() {
const CustomLink = React.forwardRef<any, Omit<LinkProps, "to">>(
(props, ref) => <Link ref={ref} to="login" {...props} />
);
return (
<MemoryRouter initialEntries={["/drafts"]} initialIndex={0}>
<li>
<ListItem button component={CustomLink} />
</li>
</MemoryRouter>
);
} |
|
@zaneclaes Great! Happy to hear the issue is resolved. It also doesn't seem there is any room for us to improve the documentation or the implementation.
The objective was to bring clarity. It seemed that the conversion switched from JavaScript error to TypeScript at some point for unclear reasons. It would have probably been confusing for an external reader. |
I searched the docs for |
|
@zaneclaes Did you find this demo? https://next.material-ui.com/guides/composition/#list, it matches your use case. |
|
Huh, I stand corrected! I don't know how I missed that. Thanks for pointing it out. Here are the places I read during the course of this investigation:
I'm convinced you're right, though since this is a breaking change, I still think the migration path should be more obvious ;) Hopefully just before the public release, a list of all the breaking changes can be compiled to aid in migration. |
|
@eps1lon Should we migrate the code snippets in https://next--material-ui.netlify.app/guides/composition/#caveat-with-inlining to TypeScript? |
|
FWIW, I really like how so many of the examples have both JS and Typescript. It'd be great if that were universal, though again, I know this isn't a priority |
|
@zaneclaes I would propose the following diff, in case you want to work on a pull request :). I think that at this point, it's easier to remove the types than to add them. diff --git a/docs/src/pages/guides/composition/composition.md b/docs/src/pages/guides/composition/composition.md
index 94d087025b..0c0aeebe07 100644
--- a/docs/src/pages/guides/composition/composition.md
+++ b/docs/src/pages/guides/composition/composition.md
@@ -85,15 +85,15 @@ function ListItemLink(props) {
The solution is simple: **avoid inline functions and pass a static component to the `component` prop** instead.
Let's change the `ListItemLink` component so `CustomLink` always reference the same component:
-```jsx
-import { Link } from 'react-router-dom';
+```tsx
+import { Link, LinkProps } from 'react-router-dom';
function ListItemLink(props) {
const { icon, primary, to } = props;
const CustomLink = React.useMemo(
() =>
- React.forwardRef((linkProps, ref) => (
+ React.forwardRef<any, Omit<LinkProps, 'to'>>((linkProps, ref) => (
<Link ref={ref} to={to} {...linkProps} />
)),
[to], |





Prior to upgrading to the 5.x alpha, the following code from the docs worked:
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:
And:
The component does render correctly, though.
Expected Behavior🤔
No runtime errors ;)
Your Environment🌎