Skip to content

Commit

Permalink
Merge pull request #3 from kadirahq/avoid-mutating-state
Browse files Browse the repository at this point in the history
Avoid mutating state
  • Loading branch information
roonyh committed Aug 30, 2016
2 parents 1f6f3dd + 57a3328 commit b679191
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/components/PropEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,20 @@ export default class PropEditor extends React.Component {
const { name, value } = change;
const fields = this.state.fields;
const { type } = fields[name];
fields[name].valid = true;
let valid = true;
if (type === 'object') {
try {
eval(`(${value})`); // eslint-disable-line no-eval
} catch (e) {
fields[name].valid = false;
valid = false;
}
}

fields[name].value = value;
this.setState({ fields });
const changedField = {};
changedField[name] = { ...fields[name], ...{ value, valid } };
const newFields = { ...fields, ...changedField };

this.setState({ fields: newFields });
}

createKnob(name) {
Expand Down

0 comments on commit b679191

Please sign in to comment.