import { useState } from "react"; import { api } from "~/utils/api"; type CommentFormProps = { postId: string; }; const inputClassName = "w-full rounded-[18px] border border-white/12 bg-[#0b1320] px-4 py-3 text-sm text-white outline-none transition placeholder:text-[#6c7790] focus:border-[#9db6ff] focus:bg-[#101928]"; export const CommentForm = ({ postId }: CommentFormProps) => { const utils = api.useUtils(); const [body, setBody] = useState(""); const [message, setMessage] = useState(null); const createComment = api.comment.create.useMutation({ onSuccess: async () => { setBody(""); setMessage("Comment created."); await utils.post.byId.invalidate({ postId }); }, onError: (error) => { setMessage(error.message); }, }); return (

Protected write route

Add a comment

{ event.preventDefault(); setMessage(null); createComment.mutate({ body, postId, }); }} >