shan_prit

Register Component Problem

Feb 9th, 2022 (edited)
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. import React, {
  2. Fragment,
  3. useContext,
  4. useState,
  5. useMemo,
  6. useCallback,
  7. } from "react";
  8. import { useParams } from "react-router-dom";
  9. import { AuthContext } from "../../shared/context/AuthContext";
  10.  
  11. import Card from "../../shared/components/UIElements/Card";
  12.  
  13. import "./Register.css";
  14.  
  15. const Register = () => {
  16. const [isLoginMode, setIsLoginMode] = useState(false); // state creation
  17. const auth = useContext(AuthContext);
  18. const registerSubmitHandler = () => {
  19. auth.login();
  20. };
  21.  
  22. if (window.location.pathname.toString() === "/login") { // attempt to determine if we should present signup or login
  23. setIsLoginMode(true);
  24. } else {
  25. setIsLoginMode(false);
  26. }
  27.  
  28. return (
  29. <Card className="authentication">
  30. <h1>{!isLoginMode ? "signup mode" : "login mode"}</h1> // result of login or signup mode
  31. <div>
  32. <label>Email</label>
  33. <input type="text" />
  34. <label>Password</label>
  35. <input type="text" />
  36. <button onClick={registerSubmitHandler}>Register</button>
  37. <button onClick={setIsLoginMode(!isLoginMode)}>Switch mode</button> // supposed to change modes within the component
  38. </div>
  39. </Card>
  40. );
  41. };
  42.  
  43. export default Register;
Add Comment
Please, Sign In to add comment