Created
September 15, 2022 18:47
-
-
Save newerton/35844967e4da3f0e01c8168157dc16f3 to your computer and use it in GitHub Desktop.
Apply Dependency inversion principle (DIP)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Props = { | |
onSubmit: (email: string, password: string) => Promise<void> | |
} | |
const LoginForm = ({ onSubmit }: Props) => { | |
const [email, setEmail] = useState('') | |
const [password, setPassword] = useState('') | |
const handleSubmit = async (evt) => { | |
evt.preventDefault() | |
await onSubmit(email, password) | |
} | |
return ( | |
<form onSubmit={handleSubmit}> | |
<input type="email" value={email} onChange={e => setEmail(e.target.value)} /> | |
<input type="password" value={password} onChange={e => setPassword(e.target.value)} /> | |
<button type="submit">Log in</button> | |
</form> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment