Last active
December 31, 2021 17:10
-
-
Save onosendi/1bc7a0846e578473c24caa29bc9f8c69 to your computer and use it in GitHub Desktop.
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
function hasErrorsMutable(values) { | |
const errors = {}; | |
if (values.foo === 'bar') { | |
errors.foo = 'Foo has bar, no bueno'; | |
} | |
if (values.bar === 'baz') { | |
errors.bar = 'Bar has baz, no bueno'; | |
} | |
return errors; | |
} | |
// Or | |
function hasErrorsImmutable(values) { | |
let errors = {}; | |
if (values.foo === 'bar') { | |
errors = { ...errors, foo: 'Foo has bar, no bueno' }; | |
} | |
if (values.bar === 'baz') { | |
errors = { ...errors, bar: 'Bar has baz, no bueno' }; | |
} | |
return errors; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment