I’m trying to post comments for an existing post, so when the button of post ccomment is clicked, it should save the data on the database inside the Posts
column but it doesn’t work as I’m getting POST error. Is there anything wrong in Posting my data like this?
function Socialpostdetail() {
const [item, setItems] = useState([])
const [comment, setComment] = useState("")
let {resultId} = useParams();
const { Moralis, isInitialized } = useMoralis();
console.log(comment)
const { data, error, isLoading } = useMoralisQuery("Posts");
const createNewComment = async (e, content) => {
e.preventDefault()
const Posts = Moralis.Object.extend("Posts");
const query = await new Moralis.Query(Posts);
query.equalTo("title", resultId);
const newComment = Moralis.Object.extend("Comments");
const comment = new newComment();
comment.set("content", content);
comment.set("author", Moralis.User.current())
comment.save();
query.set("comments", comment)
query.save();
}
return(
<button type="submit" onClick={(e) => createNewComment(e, content)}>Post Comment</button>
)
}