Created
July 14, 2021 01:59
-
-
Save carmandomx/96a7abf92831c137d547da9136ed53b9 to your computer and use it in GitHub Desktop.
create
This file contains 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
import './App.css' | |
import { useForm } from 'react-hook-form' | |
import axios from 'axios' | |
import { useEffect, useState } from 'react' | |
function App () { | |
const { register, handleSubmit } = useForm() | |
const [postData, setPostData] = useState(null) | |
useEffect(() => { | |
const miFunc = async () => { | |
const respuesta = await axios({ | |
method: 'POST', | |
url: 'https://prof-quotes.herokuapp.com/api/quotes/', | |
data: postData | |
}) | |
console.log(respuesta) | |
} | |
if (postData) { | |
miFunc() | |
} | |
}, [postData]) | |
const onSubmit = values => { | |
setPostData(values) | |
} | |
return ( | |
<div className='App'> | |
<header className='App-header'> | |
<form onSubmit={handleSubmit(onSubmit)}> | |
<div> | |
<label> | |
Cita: | |
<input | |
{...register('quote', { | |
required: true | |
})} | |
/> | |
</label> | |
</div> | |
<div> | |
<label> | |
Clase: | |
<select {...register('class', { required: true })}> | |
<option value=''>Selecciona la clase</option> | |
<option value='class 1'> Clase 1 </option> | |
</select> | |
</label> | |
</div> | |
<button>Crear</button> | |
</form> | |
</header> | |
</div> | |
) | |
} | |
export default App |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment