React.findDOMNode comes as undefined
React.findDOMNode comes as undefined
我有
<div id="wrapper"></div>
<script type="text/jsx">
/* @jsx React.DOM*/
var Login = React.createClass({
Validate: function(){
debugger;
var username = React.findDOMNode(this.refs.username).trim();
var password = React.findDOMNode(this.refs.password).trim();
console.log('Username: ' + username + ''nPassword: ' + password);
if(username == 'username' && password == 'password'){
alert('Success');
}
else{
alert('Failure');
}
},
Clear: function(){
},
render: function(){
return(
<div className="container">
Login
<p></p>
Username: <input type="text" ref="username" /><br />
Password: <input type="password" ref="password" /><br /><br />
<input type="button" value="Submit" onClick={this.Validate} />
<input type="button" value="Clear" onClick={this.Clear} />
</div>
);
}
});
React.render(<Login />, document.getElementById('wrapper'))
</script>
React.findDOMNode
是在React v0.13中引入的,因此请确保至少使用v0.13。
在Reactv0.13中使用React.findDOMNode()
。
在早期版本中,例如v0.12,您可以使用component.getDOMNode()
this.refs.myRef.getDOMNode();
为了支持未来基于ES6的模式,React团队添加了React.findDOMNode(component)
来代替component.getDOMNode().
不确定它是什么时候发生的,但它现在似乎生活在ReactDOM ReactDOM.findDOMNode
中。
请参阅https://facebook.github.io/react/docs/top-level-api.html#reactdom.finddomnode.
React.findDOMNode
已弃用,请使用
ReactDOM.findDOMNode
在React 15.1和上
这可能与上述问题中提到的代码不太相关,但来自react文档的其他几项检查是:
- "当render返回null或false时,findDOMNode返回null。"
- "findDOMNode不能用于功能组件。"
希望这能帮助到需要帮助的人。
相关文章:
- 为什么会出现错误;未捕获的类型错误:undefined不是函数;
- /undefined在我的404错误日志中多次出现
- RequireJS向模块传递配置总是返回undefined
- JSON数组数据返回Undefined
- 为什么会出现错误,“UncaughtTypeError:undefined不是函数”
- Array.lenght = undefined
- mongoose.connect undefined不是一个函数
- JavaScript”;.方法“;返回undefined
- Uncaught TypeError:undefined不是函数-ember js
- Jquery - table.row(tr) is undefined
- jQuery可以't获取data-*属性值,返回undefined
- noty.js is returning undefined
- 将对象的列表c#传递给javascript:undefined变量时出错
- $routeParams is undefined
- React.findDOMNode comes as undefined
- $scope is coming as undefined
- ADAL.js - "Nonce is not same as undefined"
- Javascript: save canvas as image ==>未捕获的TypeError: undefined
- jquery .attr() returning as undefined
- 使用express node.js的路由,但是express.Router getting as undefined