在最新的React 15.5.1包中,如果使用babel-react-present来解析JSX文件,则会出现以下警告:
Warning: Accessing PropTypes via the main React package is deprecated. Use the prop-types package from npm instead.
warning.js:36 Warning: A Component: React.createClass is deprecated and will be removed in version 16. Use plain JavaScript classes instead. If you're not yet ready to migrate, create-react-class is available on npm as a drop-in replacement.
我的代码如下:
import React from 'react'
import ReactDOM from 'react-dom';
class Counter extends React.Component {
constructor(props) {
super(props);
this.state = {
count: 1
}
}
componentDidMount() {
setInterval( ()=> {
this.setState((prevState, props) => ({
count: prevState.count + 1
}))
}, 1000)
}
render(){
return (
<h1>{this.state.count}</h1>
)
}
}
const root = document.createElement('div');
root.id = 'app';
document.body.appendChild(root);
ReactDOM.render(
<Counter />,
document.querySelector('#app')
);
我在我的代码中没有使用React.createClass和PropTypes,但似乎babel将我的代码转换为React.createClass
和PropTypes
,如何解决?