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.

@material-ui/core 4.0.0-beta.1 Warning: Function components cannot be given refs.

See original GitHub issue

When using @material-ui/core 4.0.0-beta.1 & mui-datatables 2.0.0 I get the following warning:

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

Check the render method of `Tooltip`.
    in ViewColumnIcon (created by Tooltip)
    in Tooltip (created by WithStyles(Tooltip))
    in WithStyles(Tooltip) (created by l)
    in span (created by ForwardRef(IconButton))
    in button (created by ButtonBase)
    in ButtonBase (created by ForwardRef(ButtonBase))
    in ForwardRef(ButtonBase) (created by WithStyles(ForwardRef(ButtonBase)))
    in WithStyles(ForwardRef(ButtonBase)) (created by ForwardRef(IconButton))
    in ForwardRef(IconButton) (created by WithStyles(ForwardRef(IconButton)))
    in WithStyles(ForwardRef(IconButton)) (created by l)
    in l (created by l)
    in div (created by l)
    in div (created by ForwardRef(Toolbar))
    in ForwardRef(Toolbar) (created by WithStyles(ForwardRef(Toolbar)))
    in WithStyles(ForwardRef(Toolbar)) (created by l)
    in l (created by t)
    in t (created by WithStyles(t))
    in WithStyles(t) (created by t)
    in t (created by t)
    in div (created by ForwardRef(Paper))
    in ForwardRef(Paper) (created by WithStyles(ForwardRef(Paper)))
    in WithStyles(ForwardRef(Paper)) (created by t)
    in t (created by WithStyles(t))

I suspect it has something to do with the fact that the MUI team has changed their components to be functional and use Hooks.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:25
  • Comments:20 (2 by maintainers)

github_iconTop GitHub Comments

12reactions
gabrielliwerantcommented, Jun 3, 2019

@pfarnach Yes, support for v4 is part of the plan. That’s not a bad idea about milestones and/or issues around upgrade necessities. Trying to review some PRs and fix some bugs at the moment, but when I get some time, I can start work on an upgrade roadmap.

8reactions
dandreicommented, May 15, 2019

I’ve recently had to add material-ui tooltips to functional components and looks like this does the trick:

  • wrapping the exported component in React.forwardRef(/* ... */)
  • adding a second parameter after the props (e.g. ref: React.Ref<HTMLButtonElement>)
  • passing the ref above to the component included in the functional one

The components that trigger the warning are the mui-datatables toolbar icons (Search, etc.).

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Warning: Function components cannot be given refs
What I am struggling to understand is why I get a Warning: Function components cannot be given refs. Attempts to access this ref...
Read more >
functional components cannot be given refs - You.com | The AI ...
When using @material-ui/core 4.0.0-beta.1 & mui-datatables 2.0.0 I get the following warning: Warning: Function components cannot be given refs.
Read more >
material-ui/core/CHANGELOG.md - UNPKG
This is a reminder that all ongoing work has moved to v5. This means a feature freeze on v4. The development of v4...
Read more >
@material-ui/core | Yarn - Package Manager
React components for faster and simpler web development. Build your own design system, or start with Material Design. ... Installation. Material-UI is available ......
Read more >
Composition - Material UI - MUI
Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?. Note that you will...
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