Rev 16666 | AutorÃa | Comparar con el anterior | Ultima modificación | Ver Log |
import React, { useState } from 'react'
import { axios } from '../../utils'
import styles from './comments.module.scss'
const CommentForm = ({ image, profileUrl, sendUrl, onSubmit }) => {
const [comment, setComment] = useState('')
const handleSubmit = (e) => {
e.preventDefault()
const formData = new FormData()
formData.append('comment', comment)
axios
.post(sendUrl, formData)
.then(({ data }) => {
if (!data.success) {
return console.log('Error de envio')
}
onSubmit(data)
setComment('')
})
.catch((err) => console.log(err))
}
const handleInputChange = ({ target }) => {
setComment(target.value)
}
return (
<form className={styles.comment_form} onSubmit={handleSubmit}>
<a href={profileUrl}>
<img src={image} alt="User image" />
</a>
<input
type="text"
className="form-control"
placeholder="Escribe un comentario"
onChange={handleInputChange}
value={comment}
/>
<button type="submit" className="btn btn-primary">
Comentar
</button>
</form>
)
}
export default CommentForm