-
Notifications
You must be signed in to change notification settings - Fork 47.2k
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
Warning: Stateless function components cannot be given refs. Attempts to access this ref will fail.null after updating to React 16 #10831
Comments
Stateless functions could not be given refs even in React 15. Try converting your function component into a class component. |
Thanks for reporting the issue! We'll change the error message to show the stateless component that is causing the issue. |
@CharlesStover Thanks, but these warnings only occur after i upgraded from 15.6.1 to 16-rc3. I don't use refs in my own application code. So it's probably coming from external modules, which I have no way to trace at the moment. |
The "null" at the end should have been a stacktrace pointing you at the offending component. Seeing "null" there seems like a bug. Can you share a minimal project reproducing this please? |
I see the same error. The weird part is this from the sack trace stack_frame_overlay_proxy_console @ proxyConsole.js:56 type.js is a file that exports a json object, and it's not even imported in the src/index.js file This happened when I updated react to react@16.0.0 |
Please provide a reproducing project. There’s nothing we can discuss until there is a way to reproduce. |
@gaearon I found this bug in lib antd@2.12.8 And reproduce in: https://codesandbox.io/s/931pp9zv0p You need click on left button |
PS: I was also using the Ant Design library when this bug was reported. |
I don’t know how CodeSandbox works for sure, but it seems to me that you have duplicate Can you provide a local project reproducing it? |
I am experiencing this same error from the DragSource and DropTarget components in react-dnd after upgrading my project to react 16. |
As I already said in an earlier comment there is no need to leave a comment in this thread if you don't provide a project on GitHub that reproduces it. The warning itself is legitimate. It points out a real problem that should be fixed either in your app or a library you use. You should not be trying to pass a ref to a functional component since it won't work. React now warns you about this. However, the warning should also display a stack instead of "null" at the end. If you see "null" at the end of the message, your development environment is messed up, and you have multiple versions of React and ReactDOM in the bundle. You need to fix it yourself, there is no way we can fix it for you. To check you can run:
Do you see more than one React? That's the problem. Remove the extra one and file an issue with the library that brought it in. React should be a peer dependency, not a dependency. Do the same for
See more than one? That's the issue. Remove the extra one and file an issue with the library that brought that dependency. If after all these steps the issue is unsolved, upload your project on GitHub and provide a link. Then we can look at what's causing it. Thanks! |
@gaearon https://github.com/Luchanso/issue-react-16
Issue code: https://github.com/Luchanso/issue-react-16/blob/master/src/App.js#L6 |
I can look later problem in antd lib. |
The example was very helpful, thanks. The warning is still valid though. If I fix the bug in React, I see this: This is pointing out that MenuItem is a functional component but something here attaches a ref to it. |
OK, I have a fix for the |
when this fix will get released? |
When 16.1 is released. Which will happen within a week or two. |
React |
@gaearon I still have this problem, react and react-dom is 16.1.1 |
+1 |
I'm afraid you are not reading the thread. Please re-read my reply in #10831 (comment). Again, the warning itself is correct and should be fixed in your code. This issue is just about "null" instead of component stack in the message. That has been fixed. |
If you experience issues or believe there is a false positive in the warning please file a new issue with an example. |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
Page load throws console error:
Warning: Stateless function components cannot be given refs. Attempts to access this ref will fail.null
What is the expected behavior?
No console error. Or at least some way to trace which is the stateless component that is causing the issue.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
"react": "^16.0.0-rc.3",
Chrome Version 60.0.3112.113 (Official Build) (64-bit)
macOS Sierra 10.12.6
The text was updated successfully, but these errors were encountered: