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.

Failed prop type: Invalid prop `children` supplied to `ForwardRef(Tooltip)`. Expected an element that can hold a ref

See original GitHub issue

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

Tooltip component emits an error on children reporting that a plain function component was used instead of a react element. But a react element was passed. Using a react fragment as a children wrapper is the current workaround

Sample here

https://codesandbox.io/s/compassionate-wave-59d138?file=/src/App.js

Error should show in console

Expected behavior 🤔

When a react component and a ref can be used in the tooltip’s children no error should be emitted.

Steps to reproduce 🕹

Steps:

  1. Setup a Tooltip component with your own react component as it’s child for example

  2. Examine the console’s errors

Context 🔦

Also related with this issue

https://github.com/mui/material-ui/issues/15911

It’s pretty much the same, so a common workaround could be made perhaps. Wrapping tooltip’s children in a fragment gets rid of the error.

FYI @oliviertassinari

Your environment 🌎

`npx @mui/envinfo`
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
enigma1commented, Mar 7, 2022

And because the tooltip component causes similar issues with disabled buttons wrapped-in, I created a wrapper to get around this problem. So the wrapper could be like:

import {Tooltip} from '@mui/material';

const PatchTooltip = ({children, ...props}) =>
  <Tooltip {...props}>
    <span>{children}</span>
  </Tooltip>

export default PatchTooltip;

Then place it in a temp-workaround folder and use it.

import Tooltip from './Workarounds/Tooltip';

3reactions
enigma1commented, Mar 2, 2022

If you wrap the children of the Tooltip to a fragment it doesn’t generate an error

<Tooltip title="Something">
      <>
        <ClickAwayListener onClickAway={handleClickAway}>
          <Box sx={{ position: "relative" }}>
            <button type="button" onClick={handleClick}>
              Open menu dropdown
            </button>
            {open ? (
              <Box sx={styles}>
                Click me, I will stay visible until you click outside.
              </Box>
            ) : null}
          </Box>
        </ClickAwayListener>
      </>
    </Tooltip>

And there is no reference passed in fragments. That’s not an expected behavior

Read more comments on GitHub >

github_iconTop Results From Across the Web

material-ui v4.0.1 warning "Expected an element that can hold ...
The full warning is Warning: Failed prop type: Invalid prop 'children' supplied to 'Modal'. Expected an element that can hold a ref. Did...
Read more >
2 Answers - OneCompiler
Getting Warning: Failed prop type: Invalid prop `children` supplied to `ForwardRef(Tooltip)`. Expected an element that can hold a ref.
Read more >
Warning: Failed prop type: Invalid prop `children` supplied to ...
Warning: Failed prop type: Invalid prop `children` supplied to `ForwardRef(Typography)`, expected a ReactNode. */<Typography key={item.id}>
Read more >
invalid prop `children` supplied to `forwardref(tooltip ...
Failed prop type : Invalid prop `children` supplied to `ForwardRef(Tooltip)`. Expected an element that can hold a ref. ... Basically, material-ui expects children ......
Read more >
invalid prop `rows` of type `object` supplied to `forwardref ...
Warning: Failed prop type: Invalid prop rows of type object supplied to ForwardRef(DataGrid), expected array.` Update after i remove the Object.fromEntries.
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