Move clearQueue call to inside an useEffect (#36626)

* Move clearQueue call to inside an useEffect

That call was causing a React error (Cannot update a component while rendering a different component)

* Move queueForPage declaration to before it's use
This commit is contained in:
Nathan Silveira 2023-01-27 12:33:48 -03:00 committed by GitHub
parent f1981618ad
commit d5e2ae0474
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 6 deletions

View File

@ -1,6 +1,7 @@
/**
* External dependencies
*/
import { useEffect } from 'react';
import { compose } from '@wordpress/compose';
import { withDispatch, withSelect } from '@wordpress/data';
import { OPTIONS_STORE_NAME } from '@woocommerce/data';
@ -29,18 +30,19 @@ function CustomerEffortScoreTracksContainer( {
resolving,
clearQueue,
} ) {
if ( resolving ) {
return null;
}
const queueForPage = queue.filter(
( item ) =>
item.pagenow === window.pagenow &&
item.adminpage === window.adminpage
);
useEffect( () => {
if ( queueForPage.length ) {
clearQueue();
}
}, [ queueForPage ] );
if ( queueForPage.length ) {
clearQueue();
if ( resolving ) {
return null;
}
return (

View File

@ -0,0 +1,5 @@
Significance: patch
Type: fix
Comment: Move clearQueue call to inside an useEffect since it was updating a component while rendering another component