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.

[ListItem] ListItem is not forwarding refs

See original GitHub issue

Describe the bug

The <ListItem /> component is not forwardings refs.

Expected Behavior

The <ListItem /> component is forwardings refs.

Steps to Reproduce

See the code: https://github.com/chakra-ui/chakra-ui/blob/develop/packages/layout/src/list.tsx#L97

The <ListItem /> is defined as:

export const ListItem = (props: PropsOf<typeof chakra.li>) => (
  <chakra.li {...props} />
)

Suggested solution(s)

export const ListItem = React.forwardRef(function ListItem(
  props: PropsOf<typeof chakra.li>,
  ref: React.Ref<any>,
) {
  return (
    <chakra.li ref={ref} {...props} />
  )
})

I think this would be it? But I might be missing something and there is a reason for this. For a workaround I used <Box as="li" />.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
segunadebayocommented, Aug 6, 2020

I managed to fix it before seeing this issue. Thanks for catching that @mkaradeniz.

1reaction
ljosberinncommented, Aug 5, 2020

naturally, I forgot it, but I’ll add it as soon as Sage is done with his forwardRef change.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use Forwarding Refs with react-router-dom
I already understand the concept of Forwarding Refs and react-router-dom. But in this implementation, I'm not sure how to use it correctly.
Read more >
Forwarding Refs - React
Ref forwarding is a technique for automatically passing a ref through a component to one of its children. This is typically not necessary...
Read more >
Composition - Material UI - MUI
You can use React.forwardRef and a designated prop in your class component to forward the ref to a DOM component. Doing so should...
Read more >
Send email in a workflow - Microsoft Support
Sending an email when a list item was added in some versions of ... Note: If you do not see SharePoint 2013 Workflow...
Read more >
Build strongly typed polymorphic components with React and ...
<List component="nav"> <ListItem button> <ListItemText ... if the ref is forwarded, or ComponentPropsWithoutRef when refs are not supported.
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