-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
solution #1187
base: master
Are you sure you want to change the base?
solution #1187
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your hard work on this project! While your code generally meets the task requirements, there are a few critical issues that need to be addressed before we can approve the pull request:
-
Error Handling: The error handling in your code could be improved. For example, directly throwing errors in the
catch
block can lead to unhandled promise rejections. It's important to handle errors more gracefully, perhaps by setting an error state or notifying the user. -
Prop Default Values: Setting default values for props like
setSelectedPost
,setShowForm
, andaddFunction
to empty functions can lead to unexpected behavior. Consider making these props required instead of providing default values. -
Event Handling: The
onSubmit
function inNewCommentForm.tsx
is missing theevent
parameter, which is necessary for callingpreventDefault()
correctly. -
Fetch Error Handling: The
getUsers
call lacks error handling, which could lead to silent failures. Adding error handling will improve user feedback and prevent potential issues.
Please address these issues to ensure the functionality and reliability of your application. Keep up the great work, and don't hesitate to reach out if you need any help! 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review
button in the Reviewers tab.
src/App.tsx
Outdated
const [showForm, setShowForm] = useState(false); | ||
|
||
useEffect(() => { | ||
getUsers().then(setUsers); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding error handling for the getUsers
call to manage potential errors during the fetch operation. This will help prevent silent failures and improve user feedback.
src/App.tsx
Outdated
|
||
getUserPosts(selectedUser.id) | ||
.then(setUserPosts) | ||
.catch(() => setError(true)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error handling here sets a generic error state. Consider providing more detailed error information to the user to help diagnose issues more effectively.
src/components/NewCommentForm.tsx
Outdated
|
||
export const NewCommentForm: React.FC<Props> = ({ | ||
buttonLoader, | ||
addFunction = () => {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting a default value for addFunction
to an empty function can lead to unexpected behavior if the prop is not provided. Consider making this prop required without a default value.
src/components/NewCommentForm.tsx
Outdated
return value.trim(); | ||
}; | ||
|
||
const onSubmit = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The onSubmit
function is missing the event
parameter. You need to include event
as a parameter to use event.preventDefault()
correctly.
src/components/PostDetails.tsx
Outdated
export const PostDetails: React.FC<Props> = ({ | ||
selectedPost, | ||
showForm, | ||
setShowForm = () => {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting a default value for setShowForm
to an empty function can lead to unexpected behavior if the prop is not provided. Consider making this prop required without a default value.
src/components/PostDetails.tsx
Outdated
.catch(error => { | ||
throw error; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Throwing an error directly in the catch
block is not a good practice as it can lead to unhandled promise rejections. Consider handling the error more gracefully, perhaps by setting an error state or displaying a notification to the user.
src/components/PostsList.tsx
Outdated
userPosts, | ||
selectedPost, | ||
setShowForm, | ||
setSelectedPost = () => {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting a default value for setSelectedPost
to an empty function can lead to unexpected behavior if the prop is not provided. Consider making this prop required without a default value.
src/components/UserSelector.tsx
Outdated
users, | ||
selectedUser, | ||
setSelectedUser, | ||
setSelectedPost = () => {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting a default value for setSelectedPost
to an empty function can lead to unexpected behavior if the prop is not provided. Consider making this prop required without a default value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/components/NewCommentForm.tsx
Outdated
const [text, setText] = useState(''); | ||
const [textError, setTextError] = useState(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All states must be at the beginning of the component
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
if (selectedPost && selectedPost.id === currentPost.id) { | ||
return true; | ||
} else { | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (selectedPost && selectedPost.id === currentPost.id) { | |
return true; | |
} else { | |
return false; | |
} | |
return selectedPost && selectedPost.id === currentPost.id |
it will be the same.
https://shevchuchka.github.io/react_dynamic-list-of-posts/