Skip to content

Instantly share code, notes, and snippets.

@nightspirit
Last active February 16, 2019 10:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nightspirit/25d946ff8b519ec8aa8d592d3162c862 to your computer and use it in GitHub Desktop.
Save nightspirit/25d946ff8b519ec8aa8d592d3162c862 to your computer and use it in GitHub Desktop.
function SignIn (props) {
const [username, setUsername] = useState('')
const [password, setPassword] = useState('')
const [pending, setPending] = useState('')
const [error, setError] = useState({})
useEffect(()=>{
if(pending) {
api.signIn(username, password)
.then(res => {
if(res.ok) {
// do something when succeed
// e.g. props.history.push('dashboard')
} else {
setError(res.error)
setPending(false)
}
})
}
}, [pending])
function submit (e) {
e.preventDefault()
setPending(true)
}
return (
<form onSubmit={submit}>
<input value={username} onChange={e=>setUsername(e.target.value)} />
<input value={password} onChange={e=>setPassword(e.target.value)} />
<button type='submit' />
</form>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment