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 ( <>

Create an account

handleSubmit(e)}> {/* email */} setEmail(e.target.value)} placeholder="Email" /> {/* password */} setPassword(e.target.value)} placeholder="Password" />
{/* submit button */} {/* display success message */} {register ? (

You are registered successfully!

) : (

)} {emailExists && !register ? (

An account with this email already exists

) : (

)}
); }