mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 14:57:26 +08:00
24 lines
549 B
JavaScript
24 lines
549 B
JavaScript
import { useState, useEffect } from '@wordpress/element';
|
|
|
|
export const useScriptParams = ( requestConfig ) => {
|
|
const [ data, setData ] = useState( null );
|
|
|
|
useEffect( () => {
|
|
( async () => {
|
|
try {
|
|
const response = await fetch( requestConfig.endpoint );
|
|
const json = await response.json();
|
|
if ( json.success && json?.data?.url_params ) {
|
|
setData( json.data );
|
|
} else {
|
|
setData( false );
|
|
}
|
|
} catch ( e ) {
|
|
console.error( e );
|
|
setData( false );
|
|
}
|
|
} )();
|
|
}, [ requestConfig ] );
|
|
|
|
return data;
|
|
};
|