From 872959af976d010ce89f458bbd1795395b84d0e8 Mon Sep 17 00:00:00 2001 From: Jonas Schwabe Date: Mon, 30 Jan 2017 21:58:55 +0100 Subject: [PATCH] Do not change props inside of component --- src/browser/components/SettingsPage.jsx | 19 +++++++++++++++++++ src/browser/components/TeamList.jsx | 7 ++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/browser/components/SettingsPage.jsx b/src/browser/components/SettingsPage.jsx index f4404bf9..0ffa49bc 100644 --- a/src/browser/components/SettingsPage.jsx +++ b/src/browser/components/SettingsPage.jsx @@ -152,6 +152,23 @@ const SettingsPage = React.createClass({ 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() { var teamsRow = ( @@ -161,6 +178,8 @@ const SettingsPage = React.createClass({ showAddTeamForm={this.state.showAddTeamForm} toggleAddTeamForm={this.toggleShowTeamForm} onTeamsChange={this.handleTeamsChange} + updateTeam={this.updateTeam} + addTeam={this.addTeam} /> diff --git a/src/browser/components/TeamList.jsx b/src/browser/components/TeamList.jsx index 8e85c56c..cae42fd5 100644 --- a/src/browser/components/TeamList.jsx +++ b/src/browser/components/TeamList.jsx @@ -9,7 +9,8 @@ const TeamList = React.createClass({ onTeamsChange: React.PropTypes.func, showAddTeamForm: React.PropTypes.bool, teams: React.PropTypes.array, - toggleAddTeamForm: React.PropTypes.func + addTeam: React.PropTypes.func, + updateTeam: React.PropTypes.func }, getInitialState() { @@ -110,9 +111,9 @@ const TeamList = React.createClass({ }} onSave={(newTeam) => { if (this.props.showAddTeamForm) { - this.props.teams.push(newTeam); + this.props.addTeam(newTeam); } else { - this.props.teams[newTeam.index] = newTeam; + this.props.updateTeam(newTeam.index, newTeam); } this.setState({ showNewTeamModal: false,