Mutating React state directly is a no-no. We are doing that with the lines in EmployeeEditor.js:
save() {
this.state.originalEmployee.updateName(this.state.employee.name);
this.state.originalEmployee.updatePhone(this.state.employee.phone);
this.state.originalEmployee.updateTitle(this.state.employee.title);
this.setState({ notModified: true });
this.props.refreshList();
}
That's why the this.props.refreshList() call is needed. I have never used this.setState(this.state); before. That's needed because we are mutating state behind React's back.
I realize that, to do this properly with a setState, might seem complex to show students. We'd either have to use an immutable library, or make a deep copy. I suppose I'd recommend the latter for now, perhaps using lodash's cloneDeep?
Mutating React state directly is a no-no. We are doing that with the lines in
EmployeeEditor.js:That's why the
this.props.refreshList()call is needed. I have never usedthis.setState(this.state);before. That's needed because we are mutating state behind React's back.I realize that, to do this properly with a
setState, might seem complex to show students. We'd either have to use an immutable library, or make a deep copy. I suppose I'd recommend the latter for now, perhaps using lodash'scloneDeep?