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.

[docs] Fix React.forwardRef missing display name ESLint error

See original GitHub issue
  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

In the ListItemLink sample code in the Material-UI documentation

function ListItemLink(props: ListItemLinkProps) {
    const { icon, primary, to } = props;

    const renderLink = React.useMemo(
      () =>
        React.forwardRef<any, Omit<RouterLinkProps, 'to'>>((itemProps, ref) => (
          <RouterLink to={to} ref={ref} {...itemProps} />
        )),
      [to],
    );

    return (
      <li>
        <ListItem button component={renderLink}>
          {icon ? <ListItemIcon>{icon}</ListItemIcon> : null}
          <ListItemText primary={primary} />
        </ListItem>
      </li>
    );
  }

there is an ESLint error on React.forwardRef which prevents successful Typescript compilation, and therefore deployment of our site.

(ESLint) react/display-name: Component definition is missing a display name

 React.forwardRef<any, Omit<RouterLinkProps, 'to'>>((itemProps, ref) => (
      <RouterLink to={to} ref={ref} {...itemProps} />
    )),

Expected Behavior 🤔

No Typescript compilation error.

Context 🔦

Just replicate the demo in the documentation.

Your Environment 🌎

System: OS: Windows 10 10.0.19042 Binaries: Node: 14.16.0 - C:\Program Files\nodejs\node.EXE Yarn: Not Found npm: 6.14.9 - C:\Program Files\nodejs\npm.CMD Browsers: Chrome: 90.0.4430.85 Edge: Spartan (44.19041.906.0), Chromium (90.0.818.46) npmPackages: @material-ui/core: 4.11.3 => 4.11.3 @material-ui/data-grid: 4.0.0-alpha.24 => 4.0.0-alpha.24 @material-ui/icons: 4.11.2 => 4.11.2 @material-ui/lab: 4.0.0-alpha.57 => 4.0.0-alpha.57 @material-ui/pickers: 3.3.10 => 3.3.10 @material-ui/styles: 4.11.3 => 4.11.3 @material-ui/system: 4.11.3 @material-ui/types: 5.1.0 @material-ui/utils: 4.11.2 @types/react: 17.0.3 => 17.0.3 react: 17.0.2 => 17.0.2 react-dom: 17.0.2 => 17.0.2 typescript: 4.2.4 => 4.2.4

Chrome Version 90.0.4430.85 (Official Build) (64-bit)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
eps1loncommented, Apr 26, 2021

Thanks for the report.

Should be fixed with

-React.forwardRef<any, Omit<RouterLinkProps, 'to'>>((itemProps, ref) => (
+React.forwardRef<any, Omit<RouterLinkProps, 'to'>>(function Link(itemProps, ref) { 
  return <RouterLink to={to} ref={ref} {...itemProps} />;
}),

Fix needs to be applied to https://github.com/eps1lon/material-ui/blob/next/docs/src/pages/guides/composition/composition.md as well.

1reaction
oliviertassinaricommented, May 6, 2021

@arpitBhalla Feel free too, yes

Read more comments on GitHub >

github_iconTop Results From Across the Web

Component definition is missing display name for forwardRef
The Component definition is missing display name react/display-name message is likely coming from a tool like eslint.
Read more >
[docs] Fix React.forwardRef missing display name ESLint error
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 >
Component definition is missing display name in React
Set the `displayName` property on the component to fix the "Component definition is missing ... The error is often caused when using forwardRefs...
Read more >
Component definition is missing display name for forwardRef ...
I was trying something like this: onRender: (item: PlannerTask) => <TitleColumn item={item} /> . This gave me the error. I found two ways...
Read more >
eslint function component is not a function declaration(react ...
The Component definition is missing display name react/display-name message is likely coming from a tool like eslint. It is a linting rule that...
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