woocommerce-paypal-payments/modules/ppcp-settings/resources/js/data/settings/hooks.js

44 lines
1,003 B
JavaScript
Raw Normal View History

/**
* 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
*/
import { useDispatch } from '@wordpress/data';
import { STORE_NAME } from './constants';
import { createHooksForStore } from '../utils';
const useHooks = () => {
const { useTransient, usePersistent } = createHooksForStore( STORE_NAME );
const { persist } = useDispatch( STORE_NAME );
// Read-only flags and derived state.
const [ isReady ] = useTransient( 'isReady' );
// Persistent accessors.
const [ settings, setSettings ] = usePersistent( 'settings' );
return {
persist,
isReady,
settings,
setSettings,
};
};
2025-01-21 13:15:05 +01:00
export const useStore = () => {
const { persist, isReady } = useHooks();
return { persist, isReady };
};
export const useSettings = () => {
const { settings, setSettings } = useHooks();
return {
settings,
setSettings,
};
};