Created
February 24, 2023 17:34
-
-
Save vinibgoulart/845aefd6cd5c086417c7933e6760fbc6 to your computer and use it in GitHub Desktop.
formik - get dirty values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getDirtyValues = <T>(values, initialObject: T): object => { | |
const data = { ...values }; | |
const keyValues = Object.keys(data); | |
const dirtyValues = keyValues.filter( | |
(keyValue) => data[keyValue] !== initialObject[keyValue], | |
); | |
keyValues.forEach((key) => { | |
if (!dirtyValues.includes(key)) delete data[key]; | |
}); | |
return data; | |
}; | |
export { getDirtyValues }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
example: