File tree Expand file tree Collapse file tree 1 file changed +8
-12
lines changed Expand file tree Collapse file tree 1 file changed +8
-12
lines changed Original file line number Diff line number Diff line change @@ -270,7 +270,14 @@ export const Form = (props: FormProps) => {
270
270
const [ formInstance , setFormInstance ] = useState < Webform | null > ( null ) ;
271
271
272
272
useEffect ( ( ) => {
273
- let ignore = false ;
273
+ return ( ) => {
274
+ if ( formInstance ) {
275
+ formInstance . destroy ( true ) ;
276
+ }
277
+ } ;
278
+ } , [ formInstance ] ) ;
279
+
280
+ useEffect ( ( ) => {
274
281
const createInstance = async ( ) => {
275
282
if ( renderElement . current === null ) {
276
283
console . warn ( 'Form element not found' ) ;
@@ -290,10 +297,6 @@ export const Form = (props: FormProps) => {
290
297
) ;
291
298
292
299
if ( instance ) {
293
- if ( ignore ) {
294
- instance . destroy ( true ) ;
295
- return ;
296
- }
297
300
if ( typeof formSource === 'string' ) {
298
301
instance . src = formSource ;
299
302
} else if ( typeof formSource === 'object' ) {
@@ -314,13 +317,6 @@ export const Form = (props: FormProps) => {
314
317
} ;
315
318
316
319
createInstance ( ) ;
317
- return ( ) => {
318
- ignore = true ;
319
- if ( formInstance ) {
320
- formInstance . destroy ( true ) ;
321
- }
322
- } ;
323
- // eslint-disable-next-line react-hooks/exhaustive-deps
324
320
} , [
325
321
formConstructor ,
326
322
formReadyCallback ,
You can’t perform that action at this time.
0 commit comments