Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
import React, { useState } from 'react'import { axios } from '../../utils'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="d-flex w-100" onSubmit={handleSubmit}><a href={profileUrl}><imgclassName="avatar-img rounded-circle"src={image}alt="user avatar image"/></a><inputtype="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