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) => {
270270 const [ formInstance , setFormInstance ] = useState < Webform | null > ( null ) ;
271271
272272 useEffect ( ( ) => {
273- let ignore = false ;
273+ return ( ) => {
274+ if ( formInstance ) {
275+ formInstance . destroy ( true ) ;
276+ }
277+ } ;
278+ } , [ formInstance ] ) ;
279+
280+ useEffect ( ( ) => {
274281 const createInstance = async ( ) => {
275282 if ( renderElement . current === null ) {
276283 console . warn ( 'Form element not found' ) ;
@@ -290,10 +297,6 @@ export const Form = (props: FormProps) => {
290297 ) ;
291298
292299 if ( instance ) {
293- if ( ignore ) {
294- instance . destroy ( true ) ;
295- return ;
296- }
297300 if ( typeof formSource === 'string' ) {
298301 instance . src = formSource ;
299302 } else if ( typeof formSource === 'object' ) {
@@ -314,13 +317,6 @@ export const Form = (props: FormProps) => {
314317 } ;
315318
316319 createInstance ( ) ;
317- return ( ) => {
318- ignore = true ;
319- if ( formInstance ) {
320- formInstance . destroy ( true ) ;
321- }
322- } ;
323- // eslint-disable-next-line react-hooks/exhaustive-deps
324320 } , [
325321 formConstructor ,
326322 formReadyCallback ,
You can’t perform that action at this time.
0 commit comments