-4

Simple question but I'm stuck

I have a form that returns errors

I want to capture some of the error in a useState.

The errors I don't want to capture have these codes.

const errorCodes = ['incomplete_number', 'incomplete_expiry', 'incomplete_cvc', 'incomplete_zip']

How can I capture the errors I do want that don't have those codes

if (error) {
    // eslint-disable-next-line no-restricted-syntax
    const errorCodes = ['incomplete_number', 'incomplete_expiry', 'incomplete_cvc', 'incomplete_zip']
    if (error.code is not in errorCodes[]) {
        setErrorMessage(error.message)
    }
}
lomine
  • 873
  • 5
  • 20
  • 36
  • 2
    You don't have to guess which methods exist. Simply look at a JavaScript documentation about arrays and look at the available methods, like [MDN: Array includes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes) – Peter Krebs Aug 15 '23 at 15:04
  • 1
    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray !! :/ – Mister Jojo Aug 15 '23 at 15:04
  • `if (!errorCodes.contains(error.code)) setErrorMessage(error.message);` – r3mainer Aug 15 '23 at 15:05

0 Answers0