Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This is what I call clean coding
updateStepFourProps(type, operation, data) {
let localData = [];
if (operation === 'add') {
if (type === 'educationalBackground') {
// Create Local Copy
localData = this.state.educationalBackground;
// Push Data In Local Copy
localData.push(data);
} else if (type === 'academicCertificates') {
// Create Local Copy
localData = this.state.academicCertificates;
// Push Data In Local Copy
localData.push(data);
}
} else if (operation === 'remove') {
if (type === 'educationalBackground') {
// Create Local Copy
localData = this.state.educationalBackground.filter((item) => {
return item.id !== data;
});
} else if (type === 'academicCertificates') {
// Create Local Copy
localData = this.state.academicCertificates.filter((item) => {
return item.id !== data;
});
}
}
// Set New State
this.setState({
[type]: localData,
}, () => {
// Clear localData after you're done with it
localData = [];
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.