Skip to content
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 #2589

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

KrivorotkoYurii
Copy link


let visibleTodos = todos;

switch (selectedFilter) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better move this switch-case statement to function. The perfect variant will be utils/getFilteredTodos.ts

<p className="control">
<span className="select">
<select data-cy="statusSelect" onChange={onSelectChange}>
<option value="all">All</option>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to refactor this select for using map method

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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! 🎉 While there are minor issues to be improved, they don't impact the functionality or security of the code significantly. Please pay attention to the points raised, they will help you write even better code in the future. Keep up the good work! 👍

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

const [selectedFilter, setSelectedFilter] = useState('all');
const [query, setQuery] = useState('');

const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method name 'handleInputChange' does not follow the naming conventions for event handlers in React. Please refer to the link provided in the checklist for the recommended naming conventions.

setQuery('');
};

const handleSelectChange = (event: React.ChangeEvent<HTMLSelectElement>) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method name 'handleSelectChange' does not follow the naming conventions for event handlers in React. Please refer to the link provided in the checklist for the recommended naming conventions.

setSelectedFilter(event.target.value);
};

const handleSelectTodo = (todo: Todo) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method name 'handleSelectTodo' does not follow the naming conventions for event handlers in React. Please refer to the link provided in the checklist for the recommended naming conventions.

setSelectedTodo(todo);
};

const handleResetSelectedTodo = () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method name 'handleResetSelectedTodo' does not follow the naming conventions for event handlers in React. Please refer to the link provided in the checklist for the recommended naming conventions.

@@ -17,18 +73,35 @@
<h1 className="title">Todos:</h1>

<div className="block">
<TodoFilter />
<TodoFilter
onSelectChange={handleSelectChange}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key 'onSelectChange' does not follow the naming conventions for event handlers in React. Please refer to the link provided in the checklist for the recommended naming conventions.

data-cy="selectButton"
className="button"
type="button"
onClick={() => onSelectTodo(todo)}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a minor performance issue. It's generally a good practice to avoid creating new functions inside the render method. Every time this component re-renders, a new function is created in memory. This can be avoided by defining a method on the component that takes the necessary argument, in this case, todo. You could define a method like handleSelectTodo = (todo) => () => { onSelectTodo(todo) } and then use it here like onClick={this.handleSelectTodo(todo)}.

.finally(() => setLoadingTodoModal(false));
}, [selectedTodo.userId]);

const handleResetUserAndTodo = () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of this function is not clear. According to the react naming conventions, it should start with 'handle' and then describe what it does. For example, you could rename it to 'handleResetUserAndTodo'.

getUser(selectedTodo.userId)
.then(setUser)
.finally(() => setLoadingTodoModal(false));
}, [selectedTodo.userId]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are initializing the state with props, which can lead to bugs and make the component harder to understand. It's better to initialize the state with a default value and then update it based on the props in the useEffect hook.


export const TodoModal: React.FC = () => {
return (

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are interacting with the DOM directly here by setting the class name. This is against the react way of doing things. Instead, you should use the classnames library to conditionally set the class name based on the state or props.

return (
<div className="modal is-active" data-cy="modal">
<div className="modal-background" />

{true ? (
{loadingTodoModal ? (

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are generating the key on render here. This can lead to performance issues because react uses the key to identify elements and if the key changes on every render, react will think it's a new element and will re-render it. Instead, you should generate the key when the data is created or received.

@RostyslavSharuiev
Copy link

Good work🔥🔥🔥
Just check some comments)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants