TypeError:__ WWEPACK_IMPORTED_MODULE_0_react ___ default.a.createRef不是函数 [英] TypeError: __WEBPACK_IMPORTED_MODULE_0_react___default.a.createRef is not a function

查看:366
本文介绍了TypeError:__ WWEPACK_IMPORTED_MODULE_0_react ___ default.a.createRef不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是React.js的新手,刚才我在React中学习了 ref 的概念。他们在V16.3中有新的 createRef API 。我试图从

解决方案

你似乎没有安装了正确的反应版本



执行此操作:

  npm install --save react@16.4.0 react-dom@16.4.0 


I am new to React.js and just now i was learning the concept of ref in React. They have new createRef API in V16.3. I was trying to learn this from REACT DOC's like this -

import React from "react";

export class MyComponent extends React.Component {

constructor(props) {
    super(props);
    // create a ref to store the textInput DOM element
    this.textInput = React.createRef();
    this.focusTextInput = this.focusTextInput.bind(this);
}

focusTextInput() {
    // Explicitly focus the text input using the raw DOM API
    // Note: we're accessing "current" to get the DOM node
    this.textInput.current.focus();
}

render() {
    // tell React that we want to associate the <input> ref
    // with the `textInput` that we created in the constructor
    return (
        <div>
            <input
                type="text"
                ref={this.textInput} />

            <input
                type="button"
                value="Focus the text input"
                onClick={this.focusTextInput}
            />
        </div>
    );
}

}

And I was Getting this Error -

TypeError: __WEBPACK_IMPORTED_MODULE_0_react___default.a.createRef is not a function

Here is the screenshot -

解决方案

You do not seem to have the correct version of react installed

Do this :

npm install --save react@16.4.0 react-dom@16.4.0

这篇关于TypeError:__ WWEPACK_IMPORTED_MODULE_0_react ___ default.a.createRef不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆