diff --git a/src/components/NewCommentForm.tsx b/src/components/NewCommentForm.tsx index 7068cc1c0..96e213c1b 100644 --- a/src/components/NewCommentForm.tsx +++ b/src/components/NewCommentForm.tsx @@ -44,6 +44,21 @@ export const NewCommentForm: React.FC = ({ setHasBodyError(false); } + const handleNameInput = (event: React.ChangeEvent) => { + setName(event.target.value); + setHasNameError(false); + }; + + const handleEmailInput = (event: React.ChangeEvent) => { + setEmail(event.target.value); + setHasEmailError(false); + }; + + const handleBodyInput = (event: React.ChangeEvent) => { + setBody(event.target.value); + setHasBodyError(false); + }; + return (
= ({ placeholder="Name Surname" className={cn('input', { 'is-danger': hasNameError })} value={name} - onChange={event => { - setName(event.target.value); - setHasNameError(false); - }} + onChange={handleNameInput} /> @@ -103,10 +115,7 @@ export const NewCommentForm: React.FC = ({ placeholder="email@test.com" className={cn('input', { 'is-danger': hasEmailError })} value={email} - onChange={event => { - setEmail(event.target.value); - setHasEmailError(false); - }} + onChange={handleEmailInput} /> @@ -142,10 +151,7 @@ export const NewCommentForm: React.FC = ({ placeholder="Type comment here" className={cn('input', { 'is-danger': hasBodyError })} value={body} - onChange={event => { - setBody(event.target.value); - setHasBodyError(false); - }} + onChange={handleBodyInput} /> diff --git a/src/components/PostsList.tsx b/src/components/PostsList.tsx index 7a336f73a..ae0999437 100644 --- a/src/components/PostsList.tsx +++ b/src/components/PostsList.tsx @@ -14,13 +14,13 @@ export const PostsList: React.FC = ({ selectedPost, setSelectedPost, }) => { - function onButtonClick(post: Post) { + const onButtonClick = (post: Post) => () => { if (post.id === selectedPost?.id) { setSelectedPost(null); } else { setSelectedPost(post); } - } + }; return (
@@ -51,7 +51,7 @@ export const PostsList: React.FC = ({ className={cn('button is-link', { 'is-light': post.id !== selectedPost?.id, })} - onClick={() => onButtonClick(post)} + onClick={onButtonClick(post)} > {post.id === selectedPost?.id ? 'Close' : 'Open'}