-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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 #2596
base: master
Are you sure you want to change the base?
Develop #2596
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.
Well done!
const filteredTodos = (() => { | ||
const newTodos = todos.filter(todo => { | ||
const matchesFilter = (() => { | ||
switch (filterOption) { | ||
case TodoState.completed: | ||
return todo.completed; | ||
case TodoState.active: | ||
return !todo.completed; | ||
default: | ||
return true; | ||
} | ||
})(); | ||
|
||
const matchesQuery = todo.title | ||
.toLocaleLowerCase() | ||
.includes(query.toLocaleLowerCase()); | ||
|
||
return matchesFilter && matchesQuery; | ||
}); | ||
|
||
return newTodos; | ||
})(); |
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 can create folder "utils" and move this function there
className="input" | ||
placeholder="Search..." | ||
value={query} | ||
onChange={event => setQuery(event.target.value.trimStart())} |
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 don't need trim this. In example, we can write with space, and this change result
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 on the code! There are a few minor issues to address, but they don't impact the functionality of your code. Keep up the good work! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
); | ||
<tbody> | ||
{todos.map(todo => ( | ||
<tr key={todo.id} data-cy="todo" className=""> |
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 key is generated on render, which may lead to performance issues. It's better to use a unique and consistent key, like todo.id
.
data-cy="selectButton" | ||
className="button" | ||
type="button" | ||
onClick={() => setActiveTodo(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.
The naming conventions for event handlers are not followed. It is recommended to use the handle
prefix for methods that are used as event handlers. In this case, the method could be named handleSetActiveTodo
.
> | ||
<span className="icon"> | ||
<i | ||
className={!activeTodo ? 'far fa-eye' : 'far fa-eye-slash'} |
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 classnames library can be used here to conditionally set the class for this element. This will make the code cleaner and easier to read.
getUser(activeTodo.userId) | ||
.then(setTodoUser) | ||
.finally(() => setIsLoading(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.
You have an empty array as a dependency for your useEffect
hook. This means that the effect will only run once after the initial render. However, you're using activeTodo.userId
inside the effect, which is a prop. If activeTodo
changes, your effect won't run again as expected. You should include activeTodo.userId
in the dependency array to ensure that the effect runs whenever activeTodo.userId
changes.
type="button" | ||
className="delete" | ||
data-cy="modal-close" | ||
onClick={() => setActiveTodo(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.
You're directly manipulating the DOM by setting setActiveTodo
to null in your onClick
event handler. In React, it's better to avoid direct DOM manipulation as much as possible. Consider using a more React-like approach, such as setting state or using context.
|
||
{' by '} | ||
|
||
<a href="mailto:[email protected]">Leanne Graham</a> | ||
{todoUser && ( | ||
<a href={`mailto:${todoUser.email}`}>{todoUser.name}</a> |
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're generating a new function on each render by using an inline function for the href
attribute. It's better to avoid generating new functions during render because it can lead to unnecessary re-renders and negatively impact performance. Consider moving this function outside of the component or memoizing it with useCallback
.
@@ -15,25 +32,35 @@ | |||
className="modal-card-title has-text-weight-medium" | |||
data-cy="modal-header" | |||
> |
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're generating a new string on each render by using a template literal for the Todo #${activeTodo.id}
text. It's better to avoid generating new values during render because it can lead to unnecessary re-renders and negatively impact performance. Consider moving this value outside of the component or memoizing it with useMemo
.
DEMO LINK