LoginForm.jsx 728 B

12345678910111213141516171819202122
  1. import React, {useState} from "react";
  2. export const LoginForm = ({onLogin}) => {
  3. const [login, setLogin] = useState('')
  4. const [password, setPassword] = useState('')
  5. const checkButton = () => {
  6. return !(login !== '' && password.match(/^[A-Za-z]\w{5,10}$/));
  7. }
  8. const auth = () => {
  9. onLogin(login, password)
  10. }
  11. return (
  12. <>
  13. <div className="loginBox">
  14. <input type="text" value={login} onChange={(e) => setLogin(e.target.value)}/>
  15. <input type="password" value={password} onChange={(e) => setPassword(e.target.value)}/>
  16. <button disabled={checkButton()} onClick={auth}>Log In</button>
  17. </div>
  18. </>
  19. )
  20. }