【问题标题】:How i update mern 2.0 react version to (react v16.5.1)?我如何将 mern 2.0 react 版本更新为(react v16.5.1)?
【发布时间】:2018-09-19 13:27:10
【问题描述】:

我正在尝试更新 mern 2.0 样板中的 react 版本,但是有很多问题要更新。

我在这段代码中遇到了一些 util 错误。

警告:通过主 React 包访问 PropTypes 已被弃用,并将在 React v16.0 中删除。改用来自 npm 的最新可用 v15.* prop-types 包。有关使用、兼容性、迁移等的信息...

警告:通过主 React 包访问 createClass 已被弃用,并将在 React v16.0 中删除。请改用纯 JavaScript 类。如果您还没有准备好迁移,可以在 npm 上使用 create-react-class v15.* 作为临时替代品...

【问题讨论】:

    标签: node.js reactjs npm webpack mern


    【解决方案1】:

    所以你需要安装 npm prop-types 在你的 js 文件中使用 prop 类型,如下所示:

    import PropTypes from 'prop-types';
    //get rid of this line below with propTypes
    import { PropTypes } from 'react' 
    
    class Greeting extends React.Component {
      render() {
        return (
          <h1>Hello Mario! My name is {this.props.name}</h1>
        );
      }
    }
    
    Greeting.propTypes = {
      name: PropTypes.string
    };
    

    确保删除 React 类 js 文件中的引用 import {Proptypes} from React

    【讨论】:

      猜你喜欢
      • 2016-06-22
      • 1970-01-01
      • 2022-07-31
      • 2020-04-18
      • 2016-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-11
      相关资源
      最近更新 更多