Uncaught Invariant Violation: addComponentAsRefTo(...)
See original GitHub issueI am getting the next errors on console when I am instantiating a DataPicker
in the render method from my component.
Uncaught Invariant Violation: addComponentAsRefTo(...): Only a ReactOwner can have refs. You might be adding a ref to a component that was not created inside a component's
rendermethod, or you have multiple copies of React loaded
Then when I click on the datapicker input, the dialog is shown, but I got:
react-datepicker.min.js:7 Uncaught TypeError: Cannot read property 'jquery' of null
and
ReactErrorUtils.js:71 Uncaught TypeError: Cannot read property 'focus' of undefined
I am running React v0.14.8. Do you have any idea why this is happening?
Thanks
Issue Analytics
- State:
- Created 7 years ago
- Comments:6
Top Results From Across the Web
Issues - GitHub
Uncaught Error: Invariant Violation: addComponentAsRefTo(...): Only a ReactOwner can have refs. You might be adding a ref to a component that was not...
Read more >Uncaught Invariant Violation: addComponentAsRefTo ...
I have tried uninstalling the package and reinstalling to no avail. Here is my code: render() { ... var _rows = []; for ......
Read more >`Error: Invariant Violation: addComponentAsRefTo(...): Only a ...
Coding example for the question Testing: `Error: Invariant Violation: addComponentAsRefTo(...): Only a ReactOwner can have refs.` error-Reactjs.
Read more >Refs Must Have Owner Warning - React
addComponentAsRefTo (…): Only a ReactOwner can have refs. You might be adding a ref to a component that was not created inside a...
Read more >ReactJS – Invariant Violation due to refs or multiple copies of React ...
“Uncaught Invariant Violation: addComponentAsRefTo(…): Only a ReactOwner can have refs. You might be adding a ref to a component that was not created...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I was struggling with the same issue for a day. So finally in my case it was 2 different versions of React inside
node_modules
but it was somehow difficult to reproduce it - sometimesnpm
would install only one version, another time - both.There are 2 types of fix as far as I could understand:
react@15.4.0
andreact@15.6.1
.This was because in my
package.json
I had"react": "15.4.0"
while in dependency packagecommon-components
they had"^15.1.0"
. After changing version in mypackage.json
to the same version as specified incommon-components
-"^15.1.0"
- it was fixed.resolve.alias
in webpack config (I am using webpack) - found here https://stackoverflow.com/a/42411974/449345 https://stackoverflow.com/a/31170775/449345Like this:
Maybe it helps someone else.
How are you declaring your class? If it’s a functional component, it won’t work because we use refs; you’ll need to use
React.createClass
orclass Blah extends React.Component { ... }
.