简体   繁体   English

reactjs-这不是升级时的函数错误

[英]reactjs - this is not a function error on upgrade

I am actually updating https://github.com/ezequiel/react-typeahead-component this component to be compatible to react >= 0.14 but while changing the methods I just run into one error: 我实际上正在更新https://github.com/ezequiel/react-typeahead-component这个组件以兼容> = 0.14,但是在更改方法时,我遇到一个错误:

Exchange this.getDOMnode for the reason it is deprecated with this.findDOMnode it occurs an error: Uncaught TypeError: this.findDOMNode is not a function 交易所this.getDOMnode它被弃用的原因this.findDOMnode过程中出现错误: Uncaught TypeError: this.findDOMNode is not a function

So I tried a lot about that React isn't binding this automatically in 0.14 to several functions. 所以,我想了很多关于反应不具约束力this在0.14自动几个功能。 But it did not really helped me out. 但这并没有真正帮助我。

module.exports = React.createClass({
  displayName: 'Aria Status',

  propTypes: process.env.NODE_ENV === 'production' ? {} : {
    message: React.PropTypes.string
  },

  componentDidMount: function() {
    var _this = this;

    _this.setTextContent(_this.props.message).bind(this);
  },

  componentDidUpdate: function() {
    var _this = this;

    _this.setTextContent(_this.props.message).bind(this);
  },

  render: function() {
    return (
      React.createElement("span", {
        role: "status",
        "aria-live": "polite",
        style: {
          left: '-9999px',
          position: 'absolute'
        }
      })
    );
  },

  setTextContent: function(textContent) {
    this.findDOMNode().textContent = textContent || '';
  }
});

Maybe someone can point me somewhere to go ahead! 也许有人可以指出我要去的地方!

In React v 0.14 findDOMNode is deprecated you can try use refs , like this 在React v 0.14中不推荐使用findDOMNode ,您可以尝试使用refs ,就像这样

setTextContent: function(textContent) {
  this.refs.element.textContent = textContent || '';
}

or use ReactDOM.findDOMNode 或使用ReactDOM.findDOMNode

setTextContent: function(textContent) {
  ReactDOM.findDOMNode(this).textContent =  textContent || '';
}

Example

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM