0

I'm trying to pass property to react-select element from other component but I get following error

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 render method, or you have multiple copies of React loaded

I lookup online and fb documentation regading the error here https://gist.github.com/jimfb/4faa6cbfb1ef476bd105

And tried the possible solutions, but still did not fix the issue.

I'm using react ver 15.1 and the react-select is in 1.00 beta version

Here's the sample code:

In my app.js:

var options = [
    { value: 'one', label: 'One' },
    { value: 'two', label: 'Two' }
];

function logChange(val) {
    console.log("Selected: " + val);
}


ReactDOM.render(
  <some.myDiv><span><some.ffff
    options={options}
    onChange={logChange}
    key={5}

  /></span></some.myDiv>,
  document.getElementById('example')
);

In my resuable.js:

window.some = {

  "ffff":React.createClass({
        render: function() {
            return (<Select


    {...this.props}
  />);
        }
    }),
    myDiv:React.createClass({
        render: function() {
            return (<div


    {...this.props}
  />);
        }
    }),

}
Nishanth Matha
  • 5,993
  • 2
  • 19
  • 28
  • Why is it that you're adding your component to *window.some*? – Renato Back Jun 29 '16 at 01:55
  • that's just an exapmle...I'm not using correct module import or export! So, as an alternative storing all my reusable components in one `window variable` – Nishanth Matha Jun 29 '16 at 01:59
  • I've never actually seen components with composed names, like ``. Don't even know if that's supposed to work, either. – Renato Back Jun 29 '16 at 02:02
  • yep that will work..it's working for other components which I created but, isn't working only for `Select` which is imported from `react-select` – Nishanth Matha Jun 29 '16 at 02:16
  • Does it work if you swap yours with `Select` and `div` directly? The `some.x` shouldn't be the problem here, but `{...this.props}` might. If anything taking a bit of extra time to create a jsbin could help others help you debug this. – Gosha A Jun 29 '16 at 06:54
  • i had the same issue because of multiple copies of react. i fixed it by upgrading `npm to ^3.0.0` and then reinstalling `node_modules`. – Vikramaditya Jun 29 '16 at 10:02

0 Answers0