オプション1:あなたはあなたができる状態に開催されたtwoWeeksAgo
の値を表示するために:
<h2 className="headings" id="commitTotal"> Commits since {this.state.twoWeeksAgo} : {this.state.commits.length} </h2>
あなたの状態に更新、実際の方法 - dateTwoWeeksAgo()
は - 、例えば呼び出される可能性componendDidMount
ライフサイクルメソッド。ここで
https://facebook.github.io/react/docs/component-specs.html#mounting-componentdidmount
はデモです:http://codepen.io/PiotrBerebecki/pen/LRAmBr
オプション2:別の方法として、あなただけの
const App = React.createClass({
getInitialState: function() {
return {
commits: ['One', 'Two']
};
},
dateTwoWeeksAgo: function() {
return new Date().toDateString();
},
render: function() {
return (
<div>
<h2 className="headings" id="commitTotal"> Commits since {this.dateTwoWeeksAgo()} : {this.state.commits.length} </h2>
</div>
);
}
})
コードオプションなので、(http://codepen.io/PiotrBerebecki/pen/NRzzaX)のような必要な日付を返すメソッドを呼び出すことができます1:
const App = React.createClass({
getInitialState: function() {
return {
twoWeeksAgo: null,
commits: ['One', 'Two']
};
},
componentDidMount: function() {
this.dateTwoWeeksAgo();
},
dateTwoWeeksAgo: function() {
var twoWeeksAgo = new Date().toDateString();
this.setState({twoWeeksAgo: twoWeeksAgo});
},
render: function() {
return (
<div>
<h2 className="headings" id="commitTotal"> Commits since {this.state.twoWeeksAgo} : {this.state.commits.length} </h2>
</div>
);
}
})
ReactDOM.render(
<App />,
document.getElementById('app')
);
完全なコンポーネントコードを共有できますか? –
他に何が見たいですか?ファイル全体を貼り付けるのは大きすぎます。確かに、私は状態を設定した後にデータを表示する簡単な方法がありますか? –