2024-11-18 18:58:54 +01:00
|
|
|
/**
|
|
|
|
* Hooks: Provide the main API for components to interact with the store.
|
|
|
|
*
|
|
|
|
* These encapsulate store interactions, offering a consistent interface.
|
|
|
|
* Hooks simplify data access and manipulation for components.
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
*/
|
2024-11-20 17:21:09 +01:00
|
|
|
|
|
|
|
import { useSelect } from '@wordpress/data';
|
|
|
|
|
|
|
|
import { STORE_NAME } from './constants';
|
|
|
|
|
|
|
|
const useTransient = ( key ) =>
|
|
|
|
useSelect(
|
|
|
|
( select ) => select( STORE_NAME ).transientData()?.[ key ],
|
|
|
|
[ key ]
|
|
|
|
);
|
|
|
|
|
|
|
|
const usePersistent = ( key ) =>
|
|
|
|
useSelect(
|
|
|
|
( select ) => select( STORE_NAME ).persistentData()?.[ key ],
|
|
|
|
[ key ]
|
|
|
|
);
|
2024-11-21 16:14:26 +01:00
|
|
|
|
|
|
|
export const useBusyState = () => {
|
|
|
|
const { setIsBusy } = useDispatch( STORE_NAME );
|
|
|
|
const isBusy = useTransient( 'isBusy' );
|
|
|
|
|
|
|
|
return {
|
|
|
|
isBusy,
|
|
|
|
setIsBusy: useCallback( ( busy ) => setIsBusy( busy ), [ setIsBusy ] ),
|
|
|
|
};
|
|
|
|
};
|