I already define error. however, it is giving error that "TypeError: Cannot read property 'error' of undefined"
I am stock here. I will appreciate idea to go beyond this.
Thank you for your help.
Error screenshot
Signup Component code
import React , {useState} from 'react';
import { signup } from '../../../actions/auth';
const SignupComponent = () => {
const [values, setValues] = useState({
firstname: '',
lastname: '',
email: '',
phonenumber: '',
password: '',
confirmpassword: '',
howdidyouknowaboutus: '',
error: '',
loading: false,
message: '',
showForm: true
});
const {firstname, lastname, email, phonenumber, password, confirmpassword, howdidyouknowaboutus, error, loading, message, showForm} = values;
const handleSubmit = e => {
e.preventDefault();
/* console.table({firstname, lastname, email, phonenumber, password, confirmpassword,howdidyouknowaboutus,
error, loading, message, showForm}); */
setValues({...values, loading: true, error: false})
const user = {firstname, lastname, email, phonenumber, password, confirmpassword, howdidyouknowaboutus}
signup(user).then(data => {
if (data.error) { ----------------------------------------------- The line with the error
setValues({...values, error: data.error, loading: false});
}else{
setValues({
...values,
firstname: '',
lastname: '',
email: '',
phonenumber: '',
password: '',
confirmpassword: '',
howdidyouknowaboutus: '',
error: '',
loading: false,
message: data.message,
showForm: false
});
}
});
};
};
export default SignupComponent;
Thank you
signup
action, if it doesn't return data accordingly. – buzatto