-
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 #901
base: master
Are you sure you want to change the base?
solution #901
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.
Almost done!
src/App.tsx
Outdated
.catch(() => setErrorMessage(`Can't load posts from ${user.name}`)) | ||
.finally(() => setLoading(false)); | ||
} | ||
}, [user]); |
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 errorMessage
value is missing in the dependencies
}, [user]); | |
}, [user, errorMessage]); |
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.
Hi! don't understand why
.then(setComments) | ||
.catch(() => setCommentsLoadError("Can't load comments for current post")) | ||
.finally(() => setLoading(false)); | ||
}, [post]); |
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.
Add correct dependencies here
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.
don't understand why
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.
and then you dont need extra dependencies here
src/components/PostDetails.tsx
Outdated
> | ||
<div className="message-header"> | ||
<a href={`mailto:${comment.email}`} data-cy="CommentAuthor"> | ||
{comment.name} |
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.
Don't forget about the destructuring
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.
I think that destructuring is not needed here, at the top of the code there is an object with which there will be a conflict
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.
you dont need whole obj here, so you can easily to make it here
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.
And what do you suggest to do?
src/components/UserSelector.tsx
Outdated
const [userName, setUserName] = useState('Choose a user'); | ||
const dropdownSelect = useRef<HTMLDivElement>(null); | ||
|
||
function handleSelectUser(user: User) { |
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.
Use arrow functions for better readability
src/components/UserSelector.tsx
Outdated
|
||
export const UserSelector: React.FC<Props> = ({ users, onSetUser }) => { | ||
const [dropdown, setDropdown] = useState(false); | ||
const [userName, setUserName] = useState('Choose a user'); |
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 initial value should be null if there is no user. And add a conditional rendering instead
const [userName, setUserName] = useState('Choose a user'); | |
const [userName, setUserName] = useState(null); |
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.
I have initial value user === null in app.tsx
Here initial value 'Choose a user', and I don't need conditional rendering
What is the meaning of this action?
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/UserSelector.tsx
Outdated
|
||
export const UserSelector: React.FC<Props> = ({ users, onSetUser }) => { | ||
const [dropdown, setDropdown] = useState(false); | ||
const [userName, setUserName] = useState('Choose a user'); |
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/PostDetails.tsx
Outdated
function handleDeleteComment(commentId: number) { | ||
client.delete(`/comments/${commentId}`) | ||
.then(() => { | ||
setComments( | ||
current => current?.filter(item => item.id !== commentId) || null, | ||
); | ||
setCommentsDelError([]); | ||
}) | ||
.catch(() => setCommentsDelError(current => [...current, commentId])); | ||
} | ||
|
||
const handleAddNewComment = (newComment: Comment) => { | ||
setComments(current => (current ? [...current, newComment] : [newComment])); | ||
}; |
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.
Use a consistent approach.
Or arrow functions, or function declaration
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.
#901 (comment)
В цьому компоненті ми робимо dropdown, тобто іметуємо select, а в select ми ж робимо перший option ось так,
<option value="0" disabled>Choose a user...</option>
це що теж не логічно, і тут таж історія. Є змінна userName, стартове значення 'Choose a user' яке логічно відносится до назви змінної, потім це значення змінюється на обране, та й ще умовний рендерінг не треба використовувати. Якщо це зауваження тільки про логічне що змінна не може мати таке значення, то я вважаю що це зайве.
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.
Great job overall! Just couple tiny things needs to be fixed before approval)
src/components/PostDetails.tsx
Outdated
if (commentsLoadError) { | ||
setCommentsLoadError(''); | ||
} | ||
|
||
if (comments) { | ||
setComments(null); | ||
} | ||
|
||
if (addNewComment) { | ||
setAddNewComment(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.
why do you need to reset this value here, better to create a separate func for this and do it in add func after clicking on submit but not on re rendering component
.then(setComments) | ||
.catch(() => setCommentsLoadError("Can't load comments for current post")) | ||
.finally(() => setLoading(false)); | ||
}, [post]); |
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.
and then you dont need extra dependencies here
src/components/PostDetails.tsx
Outdated
> | ||
<div className="message-header"> | ||
<a href={`mailto:${comment.email}`} data-cy="CommentAuthor"> | ||
{comment.name} |
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.
you dont need whole obj here, so you can easily to make it here
#901 (comment) |
#901 (comment) |
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.
let's fix small issues in my comments.
and discuss other questions in the Slack chat. That would be faster and easier) 🙌 just tag mentors and ask your questions)
src/components/PostDetails.tsx
Outdated
</p> | ||
</div> | ||
|
||
<div className="block"> | ||
{loading && ( |
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.
use ternary operator here for conditional rendering
src/components/PostDetails.tsx
Outdated
|
||
<p className="title is-4">Comments:</p> | ||
{comments.map(comment => ( |
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.
{comments.map(comment => ( | |
{comments.map(({name, email, id, body})=> ( |
you can easily destructure your obj like this
DEMO LINK