CezaryDanielNowak / React-dotdotdot

Multiline text ellipsis for react. Demo:
https://nowak.click/react-dotdotdot/
MIT License
401 stars 54 forks source link

Error: Only a ReactOwner can have refs #20

Closed Acentelles closed 6 years ago

Acentelles commented 7 years ago

I am having the following error when importing your library into my project:

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.

It seems to be due to this line: https://github.com/CezaryDanielNowak/React-dotdotdot/blob/master/src/index.js#L47 where you have:

Dotdotdot.prototype.render = function() {
   return React.createElement(
   "div",
   { ref: "container", className: this.props.className },
   this.props.children
  );
 };

Once I change ref to id, the error disappears, but I guess it is not the most elegant solution:

Dotdotdot.prototype.render = function() {
  return React.createElement(
    "div",
    { id: "dotdotdot-container", className: this.props.className },
    this.props.children
  );
};
CezaryDanielNowak commented 6 years ago

Please test with latest version, where text reference is replaced with function one.