私はコンポーネントのライフサイクルを学習しています。私が知っているように、getDeafaultProps()は、コンポーネントが作成されているときに最初に呼び出されます。私はログをチェックして、 "私たちのデフォルトプロパティを取得する"は表示されません。どうして?なぜconsole.logが呼び出されないのですか?
あなたはes6
を使用しているため、
defaultProps
代わりの
getDefaultProps
を使用する必要があり、あなたはこのようにそれを使用する必要が
/*
* A simple React component
*/
class Application extends React.Component {
getDefaultProps() {
console.log("Getting our default properties")
}
componentWillMount() {
console.log("Before Mounting")
this.setState({count: 1});
}
render() {
return <div>
<h1>{this.state.count}</h1>
<p>
More info <a href="https://github.com/bradleyboy/codepen-react" target="_blank">here</a>.
</p>
</div>;
}
}
/*
* Render the above component into the div#app
*/
React.render(<Application />, document.getElementById('app'));
OMG !!!!!!!!!!!! – John