當我宣佈內部類getDefaultProps
功能是從React.Component
繼承這個給錯誤,如下面getDefaultProps與之反應組件類
我設置的條件在構造函數初始化props
其undefined
。
import React from "react"
import ReactDOM from "react-dom"
class App extends React.Component{
propTypes:{
techstack : React.PropTypes.string
}
constructor(){
super();
this.props.techstack === undefined ? "Rails" : ''
console.log(this.props);
}
render(){
return (<div>
<h2>{this.props.techstack} Rocks</h2>
</div>
)
}
}
ReactDOM.render(<App/>,document.getElementById("app"));
感謝提前的幫助
感謝其工作 – uzaif
愉快的編碼。 :) –