Skip to content

Commit

Permalink
solution-edited
Browse files Browse the repository at this point in the history
  • Loading branch information
yuliia-nudyk committed Sep 27, 2024
1 parent 51ccbc2 commit 07acf97
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/components/NewCommentForm.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -18,10 +18,10 @@ type FormData = {
body: string;
};

export const NewCommentForm: React.FC<Props> = memo(function NewCommentForm({
export const NewCommentForm: React.FC<Props> = ({
postId,
onCommentAdding,
}) {
}) => {
const {
register,
setValue,
Expand Down Expand Up @@ -180,4 +180,4 @@ export const NewCommentForm: React.FC<Props> = memo(function NewCommentForm({
)}
</form>
);
});
};
12 changes: 5 additions & 7 deletions src/components/PostDetails.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -13,9 +13,7 @@ type Props = {
post: Post;
};

export const PostDetails: React.FC<Props> = memo(function PostDetails({
post,
}) {
export const PostDetails: React.FC<Props> = ({ post }) => {
// #region states
const [comments, setComments] = useState<Comment[]>([]);

Expand Down Expand Up @@ -55,9 +53,9 @@ export const PostDetails: React.FC<Props> = memo(function PostDetails({
[comments],
);

const handleCommentAdd = useCallback((newComment: Comment) => {
const handleCommentAdd = (newComment: Comment) => {
setComments(currentComments => [...currentComments, newComment]);
}, []);
};
// #endregion

return (
Expand Down Expand Up @@ -110,4 +108,4 @@ export const PostDetails: React.FC<Props> = memo(function PostDetails({
</div>
</div>
);
});
};

0 comments on commit 07acf97

Please sign in to comment.