React >> State
class IssueList extends React.Component {
constructor() {
super();
this.state = { issues: issues };
//If we don't use bind, the method createTestIssue's this will be the event
setTimeout(this.createTestIssue.bind(this), 2000);
}
createIssue(newIssue) {
//Do not modify the state directly, use a clone instead
const newIssues = this.state.issues.slice();
newIssue.id = this.state.issues.length + 1;
newIssues.push(newIssue);
this.setState({ issues: newIssues });
}
createTestIssue() {
this.createIssue({
status: 'New', owner: 'Pieta', created: new Date(),
title: 'Completion date should be optional',
});
}
render() {
return (
<div>
<h1>Issue Tracker</h1>
<IssueFilter />
<hr />
<IssueTable issues={this.state.issues} />
<hr />
<IssueAdd />
</div>
);
}
}