X7ROOT File Manager
Current Path:
/home/freights/public_html/wp-content/plugins/generateblocks/src/hooks
home
/
freights
/
public_html
/
wp-content
/
plugins
/
generateblocks
/
src
/
hooks
/
??
..
??
4zxl4en7
(9.03 KB)
??
dg8glb28
(9.03 KB)
??
index.js
(530 B)
??
mlvvn743
(9.03 KB)
??
portugues.lng
(9.03 KB)
??
useAuthors.js
(1.89 KB)
??
useBlockStyles.js
(1.33 KB)
??
useDebounceState.js
(324 B)
??
useDeviceAttributes.js
(2.52 KB)
??
useDeviceType.js
(2.26 KB)
??
useInnerBlocksCount.js
(238 B)
??
useQueryReducer.js
(1.03 KB)
??
useRecordsReducer.js
(1.44 KB)
??
useSelectedBlockElements.js
(1.57 KB)
??
useStyleIndicator.js
(1.1 KB)
??
useTaxonomies.js
(659 B)
??
useTaxonomyRecords.js
(2.05 KB)
Editing: useTaxonomyRecords.js
import { isUndefined } from 'lodash'; import { useSelect } from '@wordpress/data'; import { store as coreStore } from '@wordpress/core-data'; import { useEffect } from '@wordpress/element'; import useRecordsReducer from './useRecordsReducer'; /** * Return records for a given taxonomy. * * @param {string} taxonomy The taxonomy. * @param {Object} query The query params. * @return {{isResolving: boolean, records: Object}} The result set. */ export default function useTaxonomyRecords( taxonomy, query = {} ) { return useSelect( ( select ) => { const { getEntityRecords, isResolving, } = select( coreStore ); const queryParams = Object.assign( { per_page: -1 }, query ); // We have to check for undefined "include" here and delete it // because somehow core does not return results if hasOwnProperty( 'include' ) returns true if ( queryParams.hasOwnProperty( 'include' ) && isUndefined( queryParams.include ) ) { delete queryParams.include; } const entityParams = [ 'taxonomy', taxonomy, queryParams ]; return { records: getEntityRecords( ...entityParams ) || [], isResolving: isResolving( 'getEntityRecords', entityParams ), }; }, [ taxonomy, JSON.stringify( query ) ] ); } /** * Return records for a given taxonomy but persisting previous calls. * * @param {string} taxonomy The taxonomy. * @param {Object} params The query params to retrieve the records. * @return {{records: Object, isLoading: boolean}} The result set. */ export function usePersistentTaxonomyRecords( taxonomy, params = {} ) { const { records, setRecords, query, setQuery, isLoading, setIsLoading, reset, } = useRecordsReducer( { query: params } ); useEffect( () => { reset(); }, [ taxonomy ] ); useEffect( () => { setQuery( params ); }, [ JSON.stringify( params ) ] ); const { records: data, isResolving } = useTaxonomyRecords( taxonomy, query ); useEffect( () => { setIsLoading( isResolving ); }, [ isResolving ] ); useEffect( () => { setRecords( data ); }, [ JSON.stringify( data ) ] ); return { records, isLoading, }; }
Upload File
Create Folder