Invariant Violation: addComponentAsRefTo while building
See original GitHub issueInvariant Violation: addComponentAsRefTo while building searchkit
v0.10.1
Case is that if I build with: searchkit/src/core/react/SearchkitProvider.tsx
export class SearchkitProvider extends React.Component<SearchkitProps,any> {
render(){
return (
<div>asdasd</div>
);
}
}
using by
return (
<div>
<SearchkitProvider searchkit={searchkit}>
<div>
ssss
</div>
</SearchkitProvider>
</div>
);
I get proper response, but If I change source to
export class SearchkitProvider extends React.Component<SearchkitProps,any> {
render(){
return (
<div><input ref="asdasd" /></div>
);
}
}
i get error Uncaught Error: addComponentAsRefTo(…): Only a ReactOwner can have refs. You might be adding a ref to a component that was not created inside a component’s render
method, or you have multiple copies of React loaded
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:12 (6 by maintainers)
Top Results From Across the Web
addComponentAsRefTo Invariant Violation · GitHub
myLibrary is installed into /parentProject/node_modules/myLibrary without its dev dependencies. So when I build the main project, only one copy of react gets ...
Read more >React ref not working Invariant Violation - Stack Overflow
I am having an issue with adding a ref to a react component. Below is the error message. invariant.js:39Uncaught Invariant Violation: ...
Read more >Fixing the Jest Error, "Invariant Violation
Jest sometimes fails with an error, "Invariant Violation: addComponentAsRefTo". This how-to discusses a solution for the error & speculates ...
Read more >React ref not working Invariant Violation - appsloveworld
Coding example for the question React ref not working Invariant Violation: addComponentAsRefTo-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 >
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
OK i got a starter project based off
create-react-app
and using beta-4. This doesn’t have the multiple ref issue. https://github.com/searchkit/searchkit-starter-appI had a similar error.
This often means that multiple React instances were loaded.
We managed to solve this by explicitly importing one single version of react:
EDIT1: adjusted path, inostia is right.
EDIT2: However, importing React like this caused errors when building in testing environment.
Module not found: ../../../node_modules/react.js in /home/runner/aod_demo/app/components/Dropdown
EDIT3: I managed to fix
Module not found
in our testing environment by adding this environment variable:NODE_PATH : $(pwd)/node_modules/