import React, { useState } from "react"; import { Form, Button } from "react-bootstrap"; import axios from "axios"; import "./register.css" export default function Register() { // initial state const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [register, setRegister] = useState(false); const [emailExists, setEmailExists] = useState(false); const handleSubmit = (e) => { console.log("inside handleSubmit") // prevent the form from refreshing the whole page e.preventDefault(); // set configurations const configuration = { method: "post", url: "http://localhost:3001/register", data: { email, password, }, }; // make the API call axios(configuration) .then((result) => { console.log("result is:", result) setRegister(true); }) .catch((error) => { setEmailExists(true); setRegister(false); console.log("error is:", error) error = new Error(); }); }; return ( <>
You are registered successfully!
) : ( )} {emailExists && !register ? (An account with this email already exists
) : ( )}