I'm trying to show login and signup in just one page, that I can click on a login link that shows me the login form.
The problem is that when I click on the login link, <a href="" onClick={() => setlogin(true)}>login?</a>
, the page gets loaded for 1s and then returns to sign up form.
Code:
import React, { ReactElement, Fragment, useState } from "react";
function LoginSignUp() {
const [login, setlogin] = useState(false);
return (
<Fragment>
{login ? (
<form className="form-signin">
<input
type="email"
id="inputEmail"
className="form-control"
placeholder="Email address"
required
/>
<input
type="password"
id="inputPassword"
className="form-control"
placeholder="Password"
required
/>
<button type="submit">Sign in</button>
</form>
) : (
<form className="form-signup">
<input
type="text"
name="username"
className="form-control"
placeholder="Username"
required
/>
<input
type="email"
name="email"
className="form-control"
placeholder="Email address"
required
/>
<input
type="password"
name="password"
className="form-control"
placeholder="Password"
required
/>
<input
type="password"
name="password2"
className="form-control"
placeholder="Confirm Password"
required
/>
<button type="submit">Sign Up</button>
</form>
)}
<p id="logintxt">
Do you already have an account? ,{" "}
<a href="" onClick={() => setlogin(true)}>
login?
</a>
</p>
</Fragment>
);
}