I want to return a Boolean value when I run formValidation(), but currently I get undefined. Strangely enough, alert and console.log are working properly.
export function formValidation(...args) {
let unfilledsObject = [];
args.map(item => {
if (this.state[item] === "" || this.state[item] === false)
unfilledsObject = [...unfilledsObject, item];
});
this.setState({ formUnfilleds: unfilledsObject }, () => {
if (this.state["formUnfilleds"].length) {
alert(
`Please fill in all neccessary fields: ${this.state.formUnfilleds}`
);
return false;
}
if (!this.state["formUnfilleds"].length) {
console.log("Validated");
return true;
}
});
}