@adyen/adyen-web
Version:
[](https://www.npmjs.com/package/@adyen/adyen-web)
3 lines (2 loc) • 945 B
JavaScript
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=()=>{var e;const t=r(m);if(!t)throw new Error("useAmount must be used within an AmountProvider");return{amount:t.amount,isZeroAuth:0===(null===(e=t.amount)||void 0===e?void 0:e.value)}},d=()=>{const e=r(m);if(!e)throw new Error("useAmount must be used within an AmountProvider");return{secondaryAmount:e.secondaryAmount}},c=({amount:e,secondaryAmount:i,providerRef:d,children:c})=>{const l=r(m),[v,p]=n(e),[A,h]=n(i);s(()=>{p(e)},[e]),a(d,()=>({update:(e,t)=>{p(e),h(t)}}));const f=u(()=>({amount:v,secondaryAmount:A}),[v,A]);return l?t(o,null,c):t(m.Provider,{value:f},c)};export{c as AmountProvider,i as useAmount,d as useSecondaryAmount};
//# sourceMappingURL=AmountProvider.js.map