Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. import React, { useRef, useState } from "react";
  2. import { useAuthDataContext } from "components/auth-provider";
  3. import { authApi } from "api";
  4.  
  5. const SignInForm = () => {
  6. const { onLogin } = useAuthDataContext();
  7.  
  8. const [error, setError] = useState(null);
  9.  
  10. /*
  11. * We use uncontrolled inputs to simplify the example
  12. */
  13. const emailInput = useRef();
  14. const pswInput = useRef();
  15.  
  16. const handleSubmit = () => {
  17. const currentFormValue = {
  18. email: emailInput.current.value,
  19. password: pswInput.current.value,
  20. };
  21.  
  22. authApi.authenticate(currentFormValue).then(onLogin).catch(setError);
  23. };
  24.  
  25. return (
  26. <div>
  27. {error ? (<span style="error">{error}</span>) : null}
  28. <input ref={emailInput} type="text" name="email" />
  29. <input ref={pswInput} type="password" name="password" />
  30. <button onClick={handleSubmit}>Sign in</button>
  31. </div>
  32. );
  33. };
  34.  
  35. export default SignInForm;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement