mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +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';
|
} from './configuration';
|
||||||
|
|
||||||
const useHooks = () => {
|
const useHooks = () => {
|
||||||
const { useTransient, usePersistent } = createHooksForStore( STORE_NAME );
|
const { useTransient } = createHooksForStore( STORE_NAME );
|
||||||
const { persist } = useDispatch( STORE_NAME );
|
const { persist, setPersistent } = useDispatch( STORE_NAME );
|
||||||
|
|
||||||
// Read-only flags and derived state.
|
// Read-only flags and derived state.
|
||||||
|
|
||||||
|
@ -38,28 +38,28 @@ const useHooks = () => {
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
const [ locationStyles, setLocationStyles ] = usePersistent( location );
|
|
||||||
|
|
||||||
const getLocationProp = useCallback(
|
const getLocationProp = useCallback(
|
||||||
( prop ) => {
|
( locatonId, prop ) => {
|
||||||
if ( undefined === persistentData[ location ]?.[ prop ] ) {
|
if ( undefined === persistentData[ locatonId ]?.[ prop ] ) {
|
||||||
console.error(
|
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(
|
const setLocationProp = useCallback(
|
||||||
( prop, value ) => {
|
( locationId, prop, value ) => {
|
||||||
setLocationStyles( {
|
const updatedStyles = {
|
||||||
...locationStyles,
|
...persistentData[ locationId ],
|
||||||
[ prop ]: value,
|
[ prop ]: value,
|
||||||
} );
|
};
|
||||||
|
|
||||||
|
setPersistent( locationId, updatedStyles );
|
||||||
},
|
},
|
||||||
[ locationStyles, setLocationStyles ]
|
[ persistentData, setPersistent ]
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue