Do not change props inside of component

This commit is contained in:
Jonas Schwabe
2017-01-30 21:58:55 +01:00
parent bb21cf56d3
commit 872959af97
2 changed files with 23 additions and 3 deletions

View File

@@ -152,6 +152,23 @@ const SettingsPage = React.createClass({
showUnreadBadge: !this.refs.showUnreadBadge.props.checked showUnreadBadge: !this.refs.showUnreadBadge.props.checked
}); });
}, },
updateTeam(index, newData) {
var teams = this.state.teams;
teams[index] = newData;
this.setState({
teams
});
},
addTeam(team) {
var teams = this.state.teams;
teams.push(team);
this.setState({
teams
});
},
render() { render() {
var teamsRow = ( var teamsRow = (
<Row> <Row>
@@ -161,6 +178,8 @@ const SettingsPage = React.createClass({
showAddTeamForm={this.state.showAddTeamForm} showAddTeamForm={this.state.showAddTeamForm}
toggleAddTeamForm={this.toggleShowTeamForm} toggleAddTeamForm={this.toggleShowTeamForm}
onTeamsChange={this.handleTeamsChange} onTeamsChange={this.handleTeamsChange}
updateTeam={this.updateTeam}
addTeam={this.addTeam}
/> />
</Col> </Col>
</Row> </Row>

View File

@@ -9,7 +9,8 @@ const TeamList = React.createClass({
onTeamsChange: React.PropTypes.func, onTeamsChange: React.PropTypes.func,
showAddTeamForm: React.PropTypes.bool, showAddTeamForm: React.PropTypes.bool,
teams: React.PropTypes.array, teams: React.PropTypes.array,
toggleAddTeamForm: React.PropTypes.func addTeam: React.PropTypes.func,
updateTeam: React.PropTypes.func
}, },
getInitialState() { getInitialState() {
@@ -110,9 +111,9 @@ const TeamList = React.createClass({
}} }}
onSave={(newTeam) => { onSave={(newTeam) => {
if (this.props.showAddTeamForm) { if (this.props.showAddTeamForm) {
this.props.teams.push(newTeam); this.props.addTeam(newTeam);
} else { } else {
this.props.teams[newTeam.index] = newTeam; this.props.updateTeam(newTeam.index, newTeam);
} }
this.setState({ this.setState({
showNewTeamModal: false, showNewTeamModal: false,