-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Develop #1489
base: master
Are you sure you want to change the base?
Develop #1489
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.
LGTM!
Have just a few suggestions below
src/hooks/useTodos.ts
Outdated
const handleErrorMessage = (error: ErrorMessages) => { | ||
setErrorMessage(error); | ||
setTimeout(handleErrorReset, 3000); | ||
}; |
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 to clear timeout
src/hooks/useTodos.ts
Outdated
updateTodo(id, updatedTodo) | ||
.then(todo => { | ||
setTodos(currentTodos => | ||
currentTodos.map(t => (t.id === id ? { ...t, ...todo } : t)), |
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.
[CHECKLIST] A variable name should describe what is stored in it (it's about your variable t
)
src/hooks/useTodos.ts
Outdated
setIsReceivingAnswer(true); | ||
setLoadingTodoIds(currentIds => [ | ||
...currentIds, | ||
...completedTodos.map(todo => todo.id), | ||
]); |
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.
your function handleTodoDelete
already has this logic
src/hooks/useTodos.ts
Outdated
setIsReceivingAnswer(true); | ||
setLoadingTodoIds(currentIds => [ | ||
...currentIds, | ||
...todosToUpdate.map(todo => todo.id), | ||
]); |
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.
your function
handleTodoDelete
already has this logic
same, but this time handleTodoUpdate
src/components/Header/Header.tsx
Outdated
{todos.length > 0 && <button | ||
type="button" | ||
className={cn('todoapp__toggle-all', { | ||
active: areAllCompleted, | ||
})} | ||
data-cy="ToggleAllButton" | ||
onClick={onToggleAll} | ||
/>} |
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.
wrap <button />
in brackets for better readability
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.
Good Job 👍
let's improve your solution
src/hooks/useTodos.ts
Outdated
useEffect(() => { | ||
getTodos() | ||
.then(setTodos) | ||
.catch(() => handleErrorMessage(ErrorMessages.UNABLE_TO_LOAD_TODO)); | ||
}, []); |
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.
Move the useEffect
to the end of code
Placing useEffect
at the end improves readability by letting developers first grasp the main logic before seeing side effects. This promotes clearer structure and consistency in the codebase.
src/hooks/useTodos.ts
Outdated
useEffect(() => { | ||
getTodos() | ||
.then(setTodos) | ||
.catch(() => handleErrorMessage(ErrorMessages.UNABLE_TO_LOAD_TODO)); | ||
}, []); |
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.
It's better to move the logic inside the useEffect
hook to a separate function, as it improves code readability, reusability, and makes testing easier. It also helps keep useEffect
focused on side effects.
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.
Well done 🔥
DEMO LINK