Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 5c1f812

Browse files
try catch added
1 parent 5a54630 commit 5c1f812

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

src/forms/todo/todo.form.js

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,30 @@ function TodoForm({ onClose }) {
3232
const [formInitialValues, setFormInitialValues] = useState({});
3333

3434
useEffect(() => {
35-
if (!isEmpty(editTodoData)) {
36-
setEditMode(true);
37-
setDueDate(moment(editTodoData.dueDate));
38-
} else {
39-
setEditMode(false);
35+
try {
36+
if (!isEmpty(editTodoData)) {
37+
setEditMode(true);
38+
setDueDate(moment(editTodoData.dueDate));
39+
} else {
40+
setEditMode(false);
41+
}
42+
} catch (error) {
43+
console.log('error', error);
4044
}
4145
}, [editTodoData]);
4246

4347
useEffect(() => {
44-
const formInitialValues = {
45-
title: editMode ? editTodoData.title : undefined,
46-
description: editMode ? editTodoData.description : undefined,
47-
dueDate: editMode ? moment(editTodoData.dueDate) : TOMORROW,
48-
label: editMode ? editTodoData.label : 1,
49-
};
50-
setFormInitialValues(formInitialValues);
48+
try {
49+
const formInitialValues = {
50+
title: editMode ? editTodoData.title : undefined,
51+
description: editMode ? editTodoData.description : undefined,
52+
dueDate: editMode ? moment(editTodoData.dueDate) : TOMORROW,
53+
label: editMode ? editTodoData.label : 1,
54+
};
55+
setFormInitialValues(formInitialValues);
56+
} catch (error) {
57+
console.log('error', error);
58+
}
5159
}, [editMode]);
5260

5361
function handleSubmit(values, { setErrors, resetForm, setSubmitting }) {
@@ -88,8 +96,9 @@ function TodoForm({ onClose }) {
8896
message.success(`${values.title} ${text} successfully`);
8997
}
9098

99+
// `enableReinitialize` will solve the form not updating issue
100+
91101
return (
92-
// `enableReinitialize` will solve the form not updating issue
93102
<Formik
94103
enableReinitialize
95104
initialValues={formInitialValues}

src/pages/Todo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ export default function Todo() {
1010

1111
return (
1212
<div className="main-layout">
13-
<Row gutter={8} justify={'center'}>
13+
{/* <Row gutter={8} justify={'center'}>
1414
<Col span={8}>
1515
<TodoForm onClose={onClose} />
1616
</Col>
17-
</Row>
17+
</Row> */}
1818

1919
<Row gutter={8} justify={'end'}>
2020
<Col>

0 commit comments

Comments
 (0)