Created
August 25, 2020 14:48
-
-
Save BrunoQuaresma/3ee3bd37a6635bafe7b8e6577ddc16f9 to your computer and use it in GitHub Desktop.
Revisions
-
BrunoQuaresma created this gist
Aug 25, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ function initializeForm(form) { return Object.keys(form).reduce((newForm, key) => { let value if(form[key] === null || form[key] === undefined) { value = '' } else if(typeof form[key] === 'string') { value = form[key] } else if(typeof form[key] === 'object') { value = initializeForm(form[key]) } return { ...newForm, [key]: value } }, {}) }