Skip to content

Instantly share code, notes, and snippets.

@newerton
Created September 15, 2022 18:46
Show Gist options
  • Save newerton/bf167feaa18e1b2c118d123fddd8202c to your computer and use it in GitHub Desktop.
Save newerton/bf167feaa18e1b2c118d123fddd8202c to your computer and use it in GitHub Desktop.
Dependency inversion principle (DIP)
import api from '~/common/api'
const LoginForm = () => {
const [email, setEmail] = useState('')
const [password, setPassword] = useState('')
const handleSubmit = async (evt) => {
evt.preventDefault()
await api.login(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