Skip to content

Commit 5a23bda

Browse files
committed
Rendering the error message on UI
1 parent 28c34f9 commit 5a23bda

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/components/AddTaskForm.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { ChangeEvent, FC } from 'react'
22

33

44

5-
const AddTaskForm = ( {setToDoInput, todos, setTodos, toDoInput, toDoPosition, setToDoPosition}: any ) => {
5+
const AddTaskForm = ( {setToDoInput, todos, setTodos, toDoInput, toDoPosition, setToDoPosition, hasError, setHasError}: any ) => {
66

77
const ToDoInputHandler = function (e: ChangeEvent<HTMLInputElement>): void {
88

@@ -14,8 +14,12 @@ const AddTaskForm = ( {setToDoInput, todos, setTodos, toDoInput, toDoPosition, s
1414

1515
e.preventDefault();
1616

17-
if (e.target.value === '') {
17+
if (toDoInput !== '') {
1818
setTodos([...todos, {text: toDoInput, completed: 'false', id: Math.random() * 1000 }]);
19+
setHasError(false);
20+
}
21+
else {
22+
setHasError(true);
1923
}
2024

2125
setToDoInput('');
@@ -47,6 +51,8 @@ const AddTaskForm = ( {setToDoInput, todos, setTodos, toDoInput, toDoPosition, s
4751

4852
</div>
4953

54+
{ hasError && <div className="error-message">Please Enter a Todo</div>}
55+
5056
</form>
5157

5258
)

0 commit comments

Comments
 (0)