I have a AddContactForm form that allows the user to add contacts.
When the user fills in the conactNumber- onBlur it checks if this conactNumber already exists.
How can I make The CheckIfContactExists function returns either true or false instead of the promise object?
Please note that I can't change the returned value from the api, it only return a contact object.
export default class AddContactForm extends Component {
state = {
...
};
checkContact = () => {
const { contactNumber } = this.state.newContactInfo;
CheckIfContactExists(contactNumber); //return promise
};
render() {
...
return (
...
);
}
}
const CheckIfContactExists = async searchString => {
const { data: contactsInfo } = await axios.get(`api/Contacts/SearchContact?contactNum=${searchString}`);
};