I am trying to use the ref
property using React. I get a strange error in my browser, and I am not able to figure out what the problem is.
Can anyone explain to me why I get this error:
Error: Invariant Violation: addComponentAsRefTo(...): Only a ReactOwner can have refs. This usually means that you're trying to add a ref to a component that doesn't have an owner (that is, was not created inside of another component's
render
method). Try rendering this component inside of a new top-level component which will hold the ref.
when I have this code:
/**
* @jsx React.DOM
*/
(function(){
var react = require('react');
var App = react.createClass({
render: function() {
return (
<h1 ref="myRef">This is a test</h1>
);
}
});
react.render(
<App />,
document.body
);
}());