diff --git a/src/App.tsx b/src/App.tsx
index 7e144fe95..589344e27 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -9,7 +9,7 @@ import { Todo } from './types/types';
const initialTodos: Todo[] = todosFromServer;
function getNewTodoId(todos: Todo[]) {
- const maxId = Math.max(...todos.map(todo => todo.id));
+ const maxId = Math.max(0, ...todos.map(todo => todo.id));
return maxId + 1;
}
@@ -77,9 +77,7 @@ export const App = () => {
value={title}
onChange={handleTitle}
/>
- {hasTitleError && (
- Please enter a title{title}
- )}
+ {hasTitleError && Please enter a title}
diff --git a/src/components/UserInfo/UserInfo.tsx b/src/components/UserInfo/UserInfo.tsx
index 66358154d..f66664b91 100644
--- a/src/components/UserInfo/UserInfo.tsx
+++ b/src/components/UserInfo/UserInfo.tsx
@@ -1,17 +1,13 @@
import React from 'react';
-import { Todo, User } from '../../types/types';
-import usersFromServer from '../../api/users';
+import { Todo } from '../../types/types';
+import { getUser } from '../../utils/getUser';
type Props = {
todo: Todo;
};
-function getUser(arrUsers: User[], userId: number): User | undefined {
- return arrUsers.find(el => el.id === userId);
-}
-
export const UserInfo: React.FC
= ({ todo }) => {
- const user = getUser(usersFromServer, todo.userId);
+ const user = getUser(todo.userId);
if (!user) {
return Unknown User;
diff --git a/src/utils/getUser.ts b/src/utils/getUser.ts
new file mode 100644
index 000000000..781cc3860
--- /dev/null
+++ b/src/utils/getUser.ts
@@ -0,0 +1,6 @@
+import { User } from '../types/types';
+import usersFromServer from '../api/users';
+
+export function getUser(userId: number): User | undefined {
+ return usersFromServer.find(el => el.id === userId);
+}