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.

[4.0.0-beta.1] Wrapping function components in <Tooltip /> causes errors

See original GitHub issue

Anytime I wrap a custom component in a <Tooltip /> (for example I have a custom styled light button) I get this or similar error:

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

Those always disappear if I remove the Tooltip wrapper around my component. Tooltips aren’t working for me, I use functional components so they cannot be given refs.

  • [ x ] This is not a v0.x issue.
  • [ x ] I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior 🤔

I use a Tooltip like the docs say

      <Tooltip title="Delete">
        <IconButton aria-label="Delete">
          <DeleteIcon />
        </IconButton>
      </Tooltip>

and it works without errors.

Current Behavior 😯

const styles = {
  light: {
    color: grey[400],
    '&:hover': {
      backgroundColor: 'rgba(0, 0, 0, 0.03)',
    }
  }
};

const ButtonLight = ({ classes, type, children, ...otherProps }) => {
  switch (type) {
    case 'fab':
      return <Fab {...otherProps} className={classes.light}>{children}</Fab>;
    case 'icon':
      return <IconButton {...otherProps} className={classes.light}>{children}</IconButton>;
    case 'button':
    default:
      return <Button {...otherProps} className={classes.light}>{children}</Button>
  }
};

export default withStyles(styles)(ButtonLight)
    <Tooltip title={tooltip} placement="top">
      <ButtonLight type="icon" onClick={handleModalShow}>
        <EditIcon />
      </ButtonLight>
    </Tooltip>

Wrapping a custom component like <ButtonLight /> in a MUI <Tooltip /> results in following error:

index.js:1446 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 WithStyles(ButtonLight).

Steps to Reproduce 🕹

Link:

Context 🔦

I’m trying to, well, develop an app. The constant popping error console.logs are affecting my performance and disturbing me.

Your Environment 🌎

Tech Version
Material-UI 4.0.0-beta.1
React 16.8.6
Browser Chrome
TypeScript No
etc.
Screenshot 2019-05-11 at 10 29 54

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

21reactions
DJanoskovacommented, May 11, 2019

But functional components are the future of React. This feels like a downgrade and makes me want to move back to the old Material UI version. Since hooks are there, percentage of function components vs class components is only going to increase in projects.

Thanks for the response though.

6reactions
ShamansCodingcommented, Aug 13, 2019

As a solution to this issue, you can wrap your components with <div>. At least in my case, it did its job. ClickAwayListener cannot be wrapped by the Tooltip. I just wrapped it with div.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[4.0.0-beta.1] Wrapping function components in <Tooltip ...
Anytime I wrap a custom component in a (for example I have a custom styled light button) I get this or similar error:...
Read more >
Bootstrap - Tooltip is not working (using bootswatch)
In your presented code title was blank so the tooltip was never firing. Bootswatch doesn't seem to actually affect the look of the...
Read more >
functional components cannot be given refs - You.com | The AI ...
In React Redux 4, no ref is attached to the wrapped component by default, ... When using @material-ui/core 4.0.0-beta.1 & mui-datatables 2.0.0 I...
Read more >
material-ui/core/CHANGELOG.md - UNPKG
This release widens the peer dependency scope of React to accept ^17.0.0. 32, The change makes it easier for developers to upgrade React...
Read more >
Release Notes | GXT 4.x - Sencha Documentation
GXT 4.0.3 introduced a method in the HBLayoutContainer that causes problems with the UiBinder compile. Here's the workaround for it. Grid cell selection...
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