UNPKG

@adyen/adyen-web

Version:

[![npm](https://img.shields.io/npm/v/@adyen/adyen-web.svg)](https://www.npmjs.com/package/@adyen/adyen-web)

3 lines (2 loc) 906 B
import{createContext as e,createElement as t,Fragment as o}from"../../external/preact/dist/preact.js";import{useContext as r,useState as n,useEffect as s,useImperativeHandle as a,useMemo as u}from"../../external/preact/hooks/dist/hooks.js";const m=e(void 0),i=()=>{const e=r(m);if(!e)throw new Error("useAmount must be used within an AmountProvider");return{amount:e.amount,isZeroAuth:0===e.amount?.value}},c=()=>{const e=r(m);if(!e)throw new Error("useAmount must be used within an AmountProvider");return{secondaryAmount:e.secondaryAmount}},d=({amount:e,secondaryAmount:i,providerRef:c,children:d})=>{const l=r(m),[p,A]=n(e),[h,v]=n(i);s(()=>{A(e)},[e]),a(c,()=>({update:(e,t)=>{A(e),v(t)}}));const f=u(()=>({amount:p,secondaryAmount:h}),[p,h]);return l?t(o,null,d):t(m.Provider,{value:f},d)};export{d as AmountProvider,i as useAmount,c as useSecondaryAmount}; //# sourceMappingURL=AmountProvider.js.map