Skip to content

Instantly share code, notes, and snippets.

@farzadso
Last active December 30, 2022 08:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save farzadso/1909ec448e751cae5682fb540e01c685 to your computer and use it in GitHub Desktop.
Save farzadso/1909ec448e751cae5682fb540e01c685 to your computer and use it in GitHub Desktop.
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