I have a problem with this function in React:
createContact = (item) => {
let items = this.state.items;
let email = this.state.email;
if (items.length < 10 &&
items.includes(email) === false &&
EmailValidator.validate(email) === true) {
this.setState(state => ({
button: true,
items: state.items.concat([ item ]),
info: '✔ You have successfully added an user.'
}))
}
else if (EmailValidator.validate(email) === false) {
this.setState(state => ({
button: true,
items: state.items,
info: '! User has\'t been added - the email was invalid. Try again!'
}))
}
else if (items.includes(email) === true){
this.setState(state => ({
button: false,
items: state.items,
info: '! This email exists on this list.'
}))
}
}
The problem is, with this part of code items.includes(email)
.
I used this part of code to check, if email is on list if not.
But this always return 'false' - if email exist on list or not ...
I tried to use for this indexOf function - but it was the same ....
Maybe some of you will see the bug on this code or maybe my idea is not good ?
Thans for every tips and answers!