Con*_*tra 18 reactjs create-react-app
我正在使用create-react-app来启动React
项目.在最新的React 15.5.3
软件包中,它出现以下警告:
警告:不建议通过主React包访问PropTypes.请改用npm中的prop-types包.
我已经关注了博客:
npm install prop-types
和 import PropTypes from 'prop-types';
但它不起作用.我不使用任何代码PropTypes
或props
代码:
import React, { Component } from 'react';
import PropTypes from 'prop-types';
class App extends Component {
constructor() {
super();
this.state = {
videoVisible: true,
};
}
......
}
Run Code Online (Sandbox Code Playgroud)
如何解决?
谢谢.
Spe*_*gum 43
从Reacts博客 - npm安装prop-types,然后使用新代码.此外,它说如果嵌套组件不使用prop-types但父级是 - 所以你需要检查其他组件,你可以收到此错误消息.
// Before (15.4 and below)
import React from 'react';
class Component extends React.Component {
render() {
return <div>{this.props.text}</div>;
}
}
Component.propTypes = {
text: React.PropTypes.string.isRequired,
}
// After (15.5)
import React from 'react';
import PropTypes from 'prop-types';
class Component extends React.Component {
render() {
return <div>{this.props.text}</div>;
}
}
Component.propTypes = {
text: PropTypes.string.isRequired,
};
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
21577 次 |
最近记录: |