Skip to content

Commit e79ff57

Browse files
committed
Working with Query Parameters to switch signup/login Form
1 parent 4146cfb commit e79ff57

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

frontend/src/components/AuthForm.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
import { useState } from 'react';
2-
import { Form } from 'react-router-dom';
1+
import { Form, Link, useSearchParams } from 'react-router-dom';
32

43
import classes from './AuthForm.module.css';
54

65
function AuthForm() {
7-
const [isLogin, setIsLogin] = useState(true);
8-
9-
function switchAuthHandler() {
10-
setIsLogin((isCurrentlyLogin) => !isCurrentlyLogin);
11-
}
12-
6+
const [searchParams] = useSearchParams();
7+
const isLogin = searchParams.get('mode') === 'login';
138
return (
149
<>
1510
<Form method="post" className={classes.form}>
@@ -23,9 +18,9 @@ function AuthForm() {
2318
<input id="password" type="password" name="password" required />
2419
</p>
2520
<div className={classes.actions}>
26-
<button onClick={switchAuthHandler} type="button">
21+
<Link to={`?mode=${isLogin ? 'signup' : 'login'}`}>
2722
{isLogin ? 'Create new user' : 'Login'}
28-
</button>
23+
</Link>
2924
<button>Save</button>
3025
</div>
3126
</Form>

frontend/src/components/MainNavigation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function MainNavigation() {
4141
</li>
4242
<li>
4343
<NavLink
44-
to="/auth"
44+
to="/auth?mode=login"
4545
className={({ isActive }) =>
4646
isActive ? classes.active : undefined
4747
}

0 commit comments

Comments
 (0)