mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 14:57:26 +08:00
🥅 Add detection for accessing undefined props
This commit is contained in:
parent
033b6e5b74
commit
dac414433f
2 changed files with 12 additions and 1 deletions
|
@ -42,6 +42,11 @@ const useHooks = () => {
|
||||||
|
|
||||||
const getLocationProp = useCallback(
|
const getLocationProp = useCallback(
|
||||||
( prop ) => {
|
( prop ) => {
|
||||||
|
if ( undefined === persistentData[ location ]?.[ prop ] ) {
|
||||||
|
console.error(
|
||||||
|
`Trying to access non-existent style property: ${ location }.${ prop }. Possibly wrong style name - review the reducer.`
|
||||||
|
);
|
||||||
|
}
|
||||||
return persistentData[ location ]?.[ prop ];
|
return persistentData[ location ]?.[ prop ];
|
||||||
},
|
},
|
||||||
[ location, persistentData ]
|
[ location, persistentData ]
|
||||||
|
|
|
@ -107,7 +107,13 @@ export const createHooksForStore = ( storeName ) => {
|
||||||
`Please create the selector "${ selector }" for store "${ storeName }"`
|
`Please create the selector "${ selector }" for store "${ storeName }"`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return store[ selector ]()?.[ key ];
|
const selectorResult = store[ selector ]();
|
||||||
|
if ( undefined === selectorResult?.[ key ] ) {
|
||||||
|
console.error(
|
||||||
|
`Warning: ${ selector }()[${ key }] is undefined in store "${ storeName }". This may indicate a bug.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return selectorResult?.[ key ];
|
||||||
},
|
},
|
||||||
[ key ]
|
[ key ]
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue