File tree Expand file tree Collapse file tree 2 files changed +10
-12
lines changed Expand file tree Collapse file tree 2 files changed +10
-12
lines changed Original file line number Diff line number Diff line change 1- import React , { useState } from 'react' ;
2- import { Form } from 'react-router-dom' ;
1+ import React , { Fragment } from 'react' ;
2+ import { Form , Link , useSearchParams } from 'react-router-dom' ;
33
44import classes from './AuthForm.module.css' ;
55
66function AuthForm ( ) {
7- const [ isLogin , setIsLogin ] = useState ( true ) ;
7+ const [ searchParams ] = useSearchParams ( ) ;
88
9- function switchAuthHandler ( ) {
10- setIsLogin ( isCurrentlyLogin => ! isCurrentlyLogin ) ;
11- }
9+ const isLogin = searchParams . get ( 'mode' ) === 'login' ;
1210
1311 return (
14- < >
12+ < Fragment >
1513 < Form method = "post" className = { classes . form } >
1614 < h1 > { isLogin ? 'Log in' : 'Create a new user' } </ h1 >
1715 < p >
@@ -23,13 +21,13 @@ function AuthForm() {
2321 < input id = "password" type = "password" name = "password" required />
2422 </ p >
2523 < div className = { classes . actions } >
26- < button onClick = { switchAuthHandler } type = "button" >
24+ < Link to = { `?mode= ${ isLogin ? 'signup' : 'login' } ` } >
2725 { isLogin ? 'Create new user' : 'Login' }
28- </ button >
29- < button > Save</ button >
26+ </ Link >
27+ < button > { isLogin ? 'Login' : ' Save' } </ button >
3028 </ div >
3129 </ Form >
32- </ >
30+ </ Fragment >
3331 ) ;
3432}
3533
Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ function MainNavigation() {
4242 </ li >
4343 < li >
4444 < NavLink
45- to = "/auth"
45+ to = "/auth?mode=login "
4646 className = { ( { isActive } ) =>
4747 isActive ? classes . active : undefined
4848 }
You can’t perform that action at this time.
0 commit comments