File tree Expand file tree Collapse file tree 2 files changed +6
-11
lines changed Expand file tree Collapse file tree 2 files changed +6
-11
lines changed Original file line number Diff line number Diff line change 1
- import { useState } from 'react' ;
2
- import { Form } from 'react-router-dom' ;
1
+ import { Form , Link , useSearchParams } from 'react-router-dom' ;
3
2
4
3
import classes from './AuthForm.module.css' ;
5
4
6
5
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' ;
13
8
return (
14
9
< >
15
10
< Form method = "post" className = { classes . form } >
@@ -23,9 +18,9 @@ function AuthForm() {
23
18
< input id = "password" type = "password" name = "password" required />
24
19
</ p >
25
20
< div className = { classes . actions } >
26
- < button onClick = { switchAuthHandler } type = "button" >
21
+ < Link to = { `?mode= ${ isLogin ? 'signup' : 'login' } ` } >
27
22
{ isLogin ? 'Create new user' : 'Login' }
28
- </ button >
23
+ </ Link >
29
24
< button > Save</ button >
30
25
</ div >
31
26
</ Form >
Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ function MainNavigation() {
41
41
</ li >
42
42
< li >
43
43
< NavLink
44
- to = "/auth"
44
+ to = "/auth?mode=login "
45
45
className = { ( { isActive } ) =>
46
46
isActive ? classes . active : undefined
47
47
}
You can’t perform that action at this time.
0 commit comments