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.

`Slot` not working with `React.useImperativeHandle`

See original GitHub issue

Bug report

Current Behavior

I’m creating a custom tooltip following the docs here. Everything works well with DOM elements but when I’m using a custom component with React.useImperativeHandle it throws with

Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.

I narrowed it down to the useImperativeHandle call. If I remove it it works fine, but I need it to forward the .focus() function.

Expected behavior

It should work and not throw.

Reproducible example

CodeSandbox

Your environment

Software Name(s) Version
Radix Package(s) @radix-ui/react-polymorphic v0.0.11
@radix-ui/react-slot v0.0.10
@radix-ui/react-tooltip v0.0.18
React n/a v17.0.1
Browser Chrome v91.0.4472.101
Node n/a v12.20.0
yarn n/a v1.22.10
Operating System macOS v10.15.7

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
Kerumencommented, Jun 17, 2021

Makes sense. Feel free to close the issue if you like 😃

0reactions
benoitgrelardcommented, Jun 17, 2021

Potentially, I haven’t really looked into it yet. useImperativeHandle is also so rare that it is probably safe to ignore for now. Especially given the fact that Slot is to be used around an element, and by using useImperativeHandle you’d lose the actual DOM ref.

Read more comments on GitHub >

github_iconTop Results From Across the Web

declare type with React.useImperativeHandle() - Stack Overflow
I try to use a child method in a parent component using ref and React.useImperativeHandle() . It works well. but I am not...
Read more >
The Power of React Hooks - JSManifest
Our slotify function is invoked when the user presses the Start Quotifying button to slotify their blog post. The intention is to pop...
Read more >
Type '{}' is not assignable to type 'ReactNode'. #35986 - GitHub
The issue is that after upgrading to the last nextjs version, I am getting the error Type 'Component<{}, any, any>' is not assignable...
Read more >
The Power of React Hooks - Better Programming
This slot component takes in a quote from the user. This won't be visible to the user right away because we're going to...
Read more >
What is hidden behind React's refs ? | No Code, No Bug
Well, not quite so. We are missing one problem: what if you want the ref you attached to a React component to go...
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