zoukankan      html  css  js  c++  java
  • Uncaught TypeError: _react2.default.findDOMNode is not a function

    react 查找某节点时报错

    Uncaught TypeError: _react2.default.findDOMNode is not a function

    代码:

    import React, {Component, PropTypes} from 'react';
    class AddToDo extends Component {
        render() {
            return <div>
                <input type="text" ref="input"/>
                <button onClick={e => {
                    this.handleClick(e)
                }}>Add</button>
            </div>;
        }
        handleClick(e) {
    
            const node =  React.findDOMNode(this.refs.input);
            const text = node.value.trim();
            this.props.onAddClick(text);
            node.value = '';
        }
    }

    原因是当前我使用的React 版本中没有findDOMNode函数。

    改为引入react-dom

    import ReactDOM, {findDOMNode} from 'react-dom';

     const node =  React.findDOMNode(this.refs.input);
    改为
     const node = findDOMNode(this.refs.input);
    转载请注明出处,感谢您的配合!
  • 相关阅读:
    jvm调优
    Spring 事务
    Spring Framework入门介绍
    redis入门介绍
    Spring与SpringMVC重复扫描问题
    跨域相关问题
    Spring MVC介绍
    Servlet、Servlet容器
    获取屏幕宽高
    mybatis中比较符的写法
  • 原文地址:https://www.cnblogs.com/cheemon/p/5552295.html
Copyright © 2011-2022 走看看