Después de de una extensa recopilación de datos solucionamos este asunto que tienen muchos los lectores. Te compartimos la solución y deseamos que te sea de mucha ayuda.
Ejemplo: react bulma login
import React from 'react'
import axios from 'axios'
import useHistory from 'react-router-dom'
function Login()
const history = useHistory()
const [formData, setFormData] = React.useState(
email: '',
password: '',
)
const handleChange = (e) =>
setFormData( ...formData, [e.target.name]: e.target.value )
const handleSubmit = async (e) =>
e.preventDefault()
try
await axios.post('LOGIN API ADDRESS HERE', formData)
history.push('/')
catch (e)
console.log(e.response.data)
console.log('Form has been submitted')
return (
<sectionclassName="section"><divclassName="container"><divclassName="columns"><formclassName="column is-half is-offset-one-quarter"onSubmit=handleSubmit><divclassName="field"><labelclassName="label"htmlFor="email">
Email
label><divclassName="control"><inputclassName="input"name="email"id="email"onChange=handleChangeplaceholder="Email"/>div>div><divclassName="field"><labelclassName="label"htmlFor="password">
Password
label><divclassName="control"><inputclassName="input"name="password"id="password"type="password"onChange=handleChangeplaceholder="Password"/>div>div><divclassName="field"><buttontype="submit"className="button is-fullwidth is-warning">
Login
button>div>form>div>div>section>
)
export default Login
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)