在最新陣營15.5.1包,如果使用巴貝爾反應用來解決JSX文件,將出現以下警告:通天禁用React.createClass和PropTypes過時的警告作出反應目前
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在我的代碼,這似乎巴貝爾變換我的代碼React.createClass
和PropTypes
,如何解決呢?
您確定它來自此代碼嗎? babeljs.io似乎並不這麼認爲; [這個要點顯示你的來源和babeljs輸出](https://gist.github.com/davelnewton/495104605f24c588624f5b169075c091)。在https://babeljs.io/repl查看。你使用的是什麼版本的Babel? –
我目前遇到與新安裝的npm軟件包相同的問題。我想這可能是一些突破性變化的結果?如果在開發控制檯中,棄用警告是黃色而不是紅色,那麼 –
會很好。 –