-
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 #1054
base: master
Are you sure you want to change the base?
Solution #1054
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.
Good Job 👍
let's improve your solution
setIsLoadingTodos(true); | ||
|
||
getTodos() | ||
.then((response: Todo[]) => { | ||
dispatch(setTodos(response)); | ||
}) | ||
.catch(() => { | ||
throw new Error("Can't get todos"); | ||
}) | ||
.finally(() => setIsLoadingTodos(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.
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.
useEffect(() => { | ||
if (currentTodo) { | ||
getUser(currentTodo.userId) | ||
.then(setUser) | ||
.catch(() => { | ||
throw new Error("Can't get User information"); | ||
}) | ||
.finally(() => setIsLoading(false)); | ||
} | ||
}, [currentTodo]); |
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.
{currentTodo?.completed ? ( | ||
<strong className="has-text-success">Done</strong> | ||
) : ( | ||
<strong className="has-text-danger">Planned</strong> | ||
)} |
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 simplify this, you can render just one strong
and show the text and add className according to the condition
DEMO LINK