@@ -32,22 +32,30 @@ function TodoForm({ onClose }) {
32
32
const [ formInitialValues , setFormInitialValues ] = useState ( { } ) ;
33
33
34
34
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 ) ;
40
44
}
41
45
} , [ editTodoData ] ) ;
42
46
43
47
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
+ }
51
59
} , [ editMode ] ) ;
52
60
53
61
function handleSubmit ( values , { setErrors, resetForm, setSubmitting } ) {
@@ -88,8 +96,9 @@ function TodoForm({ onClose }) {
88
96
message . success ( `${ values . title } ${ text } successfully` ) ;
89
97
}
90
98
99
+ // `enableReinitialize` will solve the form not updating issue
100
+
91
101
return (
92
- // `enableReinitialize` will solve the form not updating issue
93
102
< Formik
94
103
enableReinitialize
95
104
initialValues = { formInitialValues }
0 commit comments