mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 14:57:26 +08:00
♻️ Location-prop accessors require a location arg
Instead of using the “location” property, we want to explicitly specify which location props to access
This commit is contained in:
parent
510a711caa
commit
a5ceec2af4
1 changed files with 14 additions and 14 deletions
|
@ -23,8 +23,8 @@ import {
|
|||
} from './configuration';
|
||||
|
||||
const useHooks = () => {
|
||||
const { useTransient, usePersistent } = createHooksForStore( STORE_NAME );
|
||||
const { persist } = useDispatch( STORE_NAME );
|
||||
const { useTransient } = createHooksForStore( STORE_NAME );
|
||||
const { persist, setPersistent } = useDispatch( STORE_NAME );
|
||||
|
||||
// Read-only flags and derived state.
|
||||
|
||||
|
@ -38,28 +38,28 @@ const useHooks = () => {
|
|||
[]
|
||||
);
|
||||
|
||||
const [ locationStyles, setLocationStyles ] = usePersistent( location );
|
||||
|
||||
const getLocationProp = useCallback(
|
||||
( prop ) => {
|
||||
if ( undefined === persistentData[ location ]?.[ prop ] ) {
|
||||
( locatonId, prop ) => {
|
||||
if ( undefined === persistentData[ locatonId ]?.[ prop ] ) {
|
||||
console.error(
|
||||
`Trying to access non-existent style property: ${ location }.${ prop }. Possibly wrong style name - review the reducer.`
|
||||
`Trying to access non-existent style property: ${ locatonId }.${ prop }. Possibly wrong style name - review the reducer.`
|
||||
);
|
||||
}
|
||||
return persistentData[ location ]?.[ prop ];
|
||||
return persistentData[ locatonId ]?.[ prop ];
|
||||
},
|
||||
[ location, persistentData ]
|
||||
[ persistentData ]
|
||||
);
|
||||
|
||||
const setLocationProp = useCallback(
|
||||
( prop, value ) => {
|
||||
setLocationStyles( {
|
||||
...locationStyles,
|
||||
( locationId, prop, value ) => {
|
||||
const updatedStyles = {
|
||||
...persistentData[ locationId ],
|
||||
[ prop ]: value,
|
||||
} );
|
||||
};
|
||||
|
||||
setPersistent( locationId, updatedStyles );
|
||||
},
|
||||
[ locationStyles, setLocationStyles ]
|
||||
[ persistentData, setPersistent ]
|
||||
);
|
||||
|
||||
return {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue