mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 09:08:09 +08:00
♻️ Implement new store-hooks accessor logic
This commit is contained in:
parent
4de4e05829
commit
13947a5d01
2 changed files with 7 additions and 20 deletions
|
@ -15,7 +15,6 @@ import { STORE_NAME } from './constants';
|
||||||
|
|
||||||
const useHooks = () => {
|
const useHooks = () => {
|
||||||
const { useTransient, usePersistent } = createHooksForStore( STORE_NAME );
|
const { useTransient, usePersistent } = createHooksForStore( STORE_NAME );
|
||||||
|
|
||||||
const { persist } = useDispatch( STORE_NAME );
|
const { persist } = useDispatch( STORE_NAME );
|
||||||
|
|
||||||
// Read-only flags and derived state.
|
// Read-only flags and derived state.
|
||||||
|
|
|
@ -6,32 +6,20 @@
|
||||||
*
|
*
|
||||||
* @file
|
* @file
|
||||||
*/
|
*/
|
||||||
import { useSelect, useDispatch } from '@wordpress/data';
|
import { useDispatch } from '@wordpress/data';
|
||||||
|
|
||||||
import { STORE_NAME } from './constants';
|
import { STORE_NAME } from './constants';
|
||||||
|
import { createHooksForStore } from '../utils';
|
||||||
const useTransient = ( key ) =>
|
|
||||||
useSelect(
|
|
||||||
( select ) => select( STORE_NAME ).transientData()?.[ key ],
|
|
||||||
[ key ]
|
|
||||||
);
|
|
||||||
|
|
||||||
const usePersistent = ( key ) =>
|
|
||||||
useSelect(
|
|
||||||
( select ) => select( STORE_NAME ).persistentData()?.[ key ],
|
|
||||||
[ key ]
|
|
||||||
);
|
|
||||||
|
|
||||||
const useHooks = () => {
|
const useHooks = () => {
|
||||||
const { persist, setSettings } = useDispatch( STORE_NAME );
|
const { useTransient, usePersistent } = createHooksForStore( STORE_NAME );
|
||||||
|
const { persist } = useDispatch( STORE_NAME );
|
||||||
|
|
||||||
// Read-only flags and derived state.
|
// Read-only flags and derived state.
|
||||||
const isReady = useTransient( 'isReady' );
|
const [ isReady ] = useTransient( 'isReady' );
|
||||||
|
|
||||||
// Persistent accessors.
|
// Persistent accessors.
|
||||||
const settings = useSelect(
|
const [ settings, setSettings ] = usePersistent( 'settings' );
|
||||||
( select ) => select( STORE_NAME ).persistentData(),
|
|
||||||
[]
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
persist,
|
persist,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue