Error message for using refs outside of render() is difficult to understand
Jignesh Kakadiya committed
Dec 26, 2013 at 12:00 UTC
2b0dc71e3d9a3396fd024c5f8d85c219c5b87aee
1 file changed
+10
-2
src/core/ReactOwner.js
+10
-2
@@ -77,7 +77,11 @@ var ReactOwner = {
77
addComponentAsRefTo: function(component, ref, owner) {
78
invariant(
79
ReactOwner.isValidOwner(owner),
80
- 'addComponentAsRefTo(...): Only a ReactOwner can have refs.'
80
+ 'addComponentAsRefTo(...): Only a ReactOwner can have refs. This ' +
81
+ 'usually means that you\'re trying to add a ref to a component that ' +
82
+ 'doesn\'t have an owner (that is, was not created inside of another ' +
83
+ 'component\'s `render` method. Try rendering this component inside of ' +
84
+ 'a new top-level component which will hold the ref.'
85
);
86
owner.attachRef(ref, component);
87
},
@@ -94,7 +98,11 @@ var ReactOwner = {
98
removeComponentAsRefFrom: function(component, ref, owner) {
99
invariant(
100
ReactOwner.isValidOwner(owner),
97
- 'removeComponentAsRefFrom(...): Only a ReactOwner can have refs.'
101
+ 'removeComponentAsRefFrom(...): Only a ReactOwner can have refs. This ' +
102
+ 'usually means that you\'re trying to remove a ref to a component that ' +
103
+ 'doesn\'t have an owner (that is, was not created inside of another ' +
104
+ 'component\'s `render` method. Try rendering this component inside of ' +
105
+ 'a new top-level component which will hold the ref.'
106
);
107
// Check that `component` is still the current ref because we do not want to
108
// detach the ref if another component stole it.