const Signup = () =>{
const [createUser, setCreateUser] = useState({
name: "",
email: "",
password: "",
error: ""
})
const handleChange =(event) =>{
const {name , value} = event.target
setCreateUser((prevValue)=>{
return{
...prevValue, [name]: value
}
})
}
const handleClick = (e) =>{
e.preventDefault();
const user = {
name, email, password
}
signup(user).then((data)=>{
if(data.error) setCreateUser({ error: data.error}); else{ setCreateUser({name: "" , email: "", password: "" , error: ""})}
})
}
const signup = (user) =>{
return axios.post('http://localhost:5000/signup', user)
.then((res)=>{
return res.json()
})
.catch((err)=>{
console.log(err)
})
}
Hello Campers i keep on getting this error when trying to show validation error to the user at
if(data.error) setCreateUser({ error: data.error}); else{ setCreateUser({name: "" , email: "", password: "" , error: ""})}
am i passing the state correctly?