Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Fix Featured Product Search not working for large stores (#5156)
Browse files Browse the repository at this point in the history
* Remove the dependency from the getProducts useEffect

* using ref instead of empty dependency array for useEffect
  • Loading branch information
alexflorisca authored Dec 2, 2021
1 parent 3879b9d commit 2c29a8d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions assets/js/hocs/with-searched-products.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { useEffect, useState, useCallback } from '@wordpress/element';
import { useEffect, useState, useCallback, useRef } from '@wordpress/element';
import { blocksConfig } from '@woocommerce/block-settings';
import { getProducts } from '@woocommerce/editor-components/utils';
import { useDebouncedCallback } from 'use-debounce';
Expand Down Expand Up @@ -41,14 +41,16 @@ const withSearchedProducts = (
setIsLoading( false );
};

const selectedRef = useRef( selected );

useEffect( () => {
getProducts( { selected } )
getProducts( { selected: selectedRef.current } )
.then( ( results ) => {
setProductsList( results as ProductResponseItem[] );
setIsLoading( false );
} )
.catch( setErrorState );
}, [ selected ] );
}, [ selectedRef ] );

const debouncedSearch = useDebouncedCallback( ( search: string ) => {
getProducts( { selected, search } )
Expand Down

0 comments on commit 2c29a8d

Please sign in to comment.