Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save carmandomx/96a7abf92831c137d547da9136ed53b9 to your computer and use it in GitHub Desktop.
Save carmandomx/96a7abf92831c137d547da9136ed53b9 to your computer and use it in GitHub Desktop.
create
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