@@ -43,20 +43,20 @@ const App = () => {
4343 ) ;
4444 const updateEndDate = useCallback ( ( movie ) => {
4545 const form = formInstanceRef . current ;
46- const formData = form . option ( 'formData' ) ;
46+ const formData = form ? .option ( 'formData' ) ;
4747 const { startDate } = formData ;
4848 if ( startDate ) {
4949 const newEndDate = new Date ( startDate . getTime ( ) + 60 * 1000 * movie . duration ) ;
50- form . updateData ( 'endDate' , newEndDate ) ;
50+ form ? .updateData ( 'endDate' , newEndDate ) ;
5151 }
5252 } , [ ] ) ;
5353 const onFormInitialized = useCallback (
5454 ( e ) => {
5555 const form = e . component ;
56- formInstanceRef . current = form ;
57- form . on ( 'fieldDataChanged' , ( fieldEvent ) => {
56+ form && ( formInstanceRef . current = form ) ;
57+ form ? .on ( 'fieldDataChanged' , ( fieldEvent ) => {
5858 if ( fieldEvent . dataField === 'startDate' ) {
59- const currentFormData = form . option ( 'formData' ) ;
59+ const currentFormData = form ? .option ( 'formData' ) ;
6060 const movie = getMovieById ( currentFormData . movieId ) ;
6161 if ( movie ) {
6262 updateEndDate ( movie ) ;
@@ -71,7 +71,7 @@ const App = () => {
7171 const form = formInstanceRef . current ;
7272 const movie = getMovieById ( e . value ) ;
7373 if ( movie ) {
74- form . updateData ( 'director' , movie . director ) ;
74+ form ? .updateData ( 'director' , movie . director ) ;
7575 updateEndDate ( movie ) ;
7676 }
7777 } ,
0 commit comments