I am performing validation on the server with Node.js and sending the response back to the client
try {
const response = await register(user);
console.log(response);
} catch (ex) {
if (ex.response && ex.response.status === 422) {
const errors = ex.response.data.errors;
this.setState({ errors });
}
}
If I console.log(this.state.errors) I get:
(5) [{…}, {…}, {…}, {…}, {…}]
0: {name: "Name required"}
1: {name: "Name should be more than 3 characters"}
2: {email: "Invalid email address"}
3: {password: "Password required"}
4: {password: "Password should be at least 6 characters"}
length: 5
__proto__: Array(0)
I then want to just loop through all the errors and display them one underneath each other.
{this.state.errors &&
this.state.errors.map(error => <li>{error}</li>)}
But I get an error that says:
this.state.errors.map is not a function