From 07acf97df7ec9dbf2bb9ede9f3ddc26a96606aad Mon Sep 17 00:00:00 2001 From: Yuliia Nudyk Date: Fri, 27 Sep 2024 12:53:15 +0300 Subject: [PATCH] solution-edited --- src/components/NewCommentForm.tsx | 8 ++++---- src/components/PostDetails.tsx | 12 +++++------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/components/NewCommentForm.tsx b/src/components/NewCommentForm.tsx index 86334883b..99a0e7f33 100644 --- a/src/components/NewCommentForm.tsx +++ b/src/components/NewCommentForm.tsx @@ -1,5 +1,5 @@ // #region imports -import React, { memo, useState } from 'react'; +import React, { useState } from 'react'; import cn from 'classnames'; import { useForm } from 'react-hook-form'; import { addPostComment } from '../services/comments'; @@ -18,10 +18,10 @@ type FormData = { body: string; }; -export const NewCommentForm: React.FC = memo(function NewCommentForm({ +export const NewCommentForm: React.FC = ({ postId, onCommentAdding, -}) { +}) => { const { register, setValue, @@ -180,4 +180,4 @@ export const NewCommentForm: React.FC = memo(function NewCommentForm({ )} ); -}); +}; diff --git a/src/components/PostDetails.tsx b/src/components/PostDetails.tsx index 9a9f7f7f3..b89ee1de7 100644 --- a/src/components/PostDetails.tsx +++ b/src/components/PostDetails.tsx @@ -1,5 +1,5 @@ // #region imports -import React, { memo, useCallback, useEffect, useState } from 'react'; +import React, { useCallback, useEffect, useState } from 'react'; import { CommentsList } from './CommentsList'; import { ErrorNotification } from './ErrorNotification'; import { Loader } from './Loader'; @@ -13,9 +13,7 @@ type Props = { post: Post; }; -export const PostDetails: React.FC = memo(function PostDetails({ - post, -}) { +export const PostDetails: React.FC = ({ post }) => { // #region states const [comments, setComments] = useState([]); @@ -55,9 +53,9 @@ export const PostDetails: React.FC = memo(function PostDetails({ [comments], ); - const handleCommentAdd = useCallback((newComment: Comment) => { + const handleCommentAdd = (newComment: Comment) => { setComments(currentComments => [...currentComments, newComment]); - }, []); + }; // #endregion return ( @@ -110,4 +108,4 @@ export const PostDetails: React.FC = memo(function PostDetails({ ); -}); +};