Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

innerRef is not working - throws React error #13803

Closed
sztrzask opened this issue Dec 4, 2018 · 2 comments
Closed

innerRef is not working - throws React error #13803

sztrzask opened this issue Dec 4, 2018 · 2 comments

Comments

@sztrzask
Copy link
Contributor

sztrzask commented Dec 4, 2018

innerRef is not working on MenuList component.

Expected Behavior 🤔

innerRef works

Current Behavior 😯

innerRef throws this error:


Warning: Function components cannot be given refs. Attempts to access this ref will fail.

Check the render method of `WithStyles(List)`.
    in List (created by WithStyles(List))
    in WithStyles(List) (created by MenuList)
    in MenuList (created by Popper)
    in ClickAwayListener (created by Popper)
    in div (created by Paper)
    in Paper (created by WithStyles(Paper))
    in WithStyles(Paper) (created by Popper)
    in Transition (created by Grow)
    in Grow (created by WithTheme(Grow))
    in WithTheme(Grow) (created by Popper)
    in div (created by Popper)
    in Portal (created by Popper)
    in Popper (created by WithTheme(Popper))
    in WithTheme(Popper) (created by MenuListComposition)
    in div (created by MenuListComposition)
    in div (created by MenuListComposition)
    in MenuListComposition (created by WithStyles(MenuListComposition))
    in WithStyles(MenuListComposition)

Steps to Reproduce 🕹

Link:https://codesandbox.io/s/9lvnk027op

  1. Click "Toggle menu grow"
  2. Look at the codesandbox console

Context 🔦

I'm trying to access the underlying ul to get access to li elements to build autoscroller to selected one element

Your Environment 🌎

Tech Version
Material-UI v3.6.1
React 16.6.3
@oliviertassinari
Copy link
Member

oliviertassinari commented Dec 4, 2018

@sztrzask The innerRef property is applied on the List functional component. The warning is expected. You can use the RootRef component instead.

In the future, #10825 should provide a clean answer.

@franklixuefei
Copy link
Contributor

franklixuefei commented Dec 17, 2018

I tried this as well, and seems like innerRef is not called when passed a function, as can be demonstrated using this code:

<Paper
    innerRef={(node) => console.log('+++', node)}
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants