import { Box, Button, Container, TextField, Typography } from "@mui/material"; import React, { useState } from "react"; import { createAlert } from "../../actions/alert"; import { addComment } from "../../actions/post"; import { useAppDispatch } from "../../utils/hooks"; const CommentForm = ({ postId }: { postId: string }) => { const [text, setText] = useState(""); const dispatch = useAppDispatch(); return ( Leave a Comment { e.preventDefault(); if (text.length > 250) { dispatch( createAlert("Comment longer than 250 characters", "danger"), ); } else { dispatch(addComment(postId, { text })); setText(""); } }} > setText(e.target.value)} /> ); }; export default CommentForm;