Server IP : 192.158.238.246 / Your IP : 3.148.179.141 Web Server : LiteSpeed System : Linux uniform.iwebfusion.net 4.18.0-553.27.1.lve.1.el8.x86_64 #1 SMP Wed Nov 20 15:58:00 UTC 2024 x86_64 User : jenniferflocom ( 1321) PHP Version : 8.1.32 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /proc/7779/cwd/plugins/give/src/DonationForms/resources/app/store/donation-summary/ |
Upload File : |
import {createContext, ReactElement, ReactNode, useContext} from 'react'; import {useImmerReducer} from 'use-immer'; import reducer from './reducer'; const StoreContext = createContext(null); StoreContext.displayName = 'DonationSummaryProvider'; const StoreContextDispatch = createContext(null); StoreContextDispatch.displayName = 'DonationSummaryDispatch'; export type DonationTotals = {[key: string]: number}; export type DonationSummaryItems = {[key: string]: DonationSummaryLineItem}; /** * @since 3.0.0 */ export type DonationSummaryLineItem = { id: string; label: string; value: string | ReactElement; description?: string | ReactElement; }; type PropTypes = { initialState?: { items: DonationSummaryItems; totals: DonationTotals; }; children: ReactNode; }; /** * @since 3.0.0 */ const DonationSummaryProvider = ({initialState = {items: {}, totals: {}}, children}: PropTypes) => { const [state, dispatch] = useImmerReducer(reducer, initialState); return ( <StoreContext.Provider value={state}> <StoreContextDispatch.Provider value={dispatch}>{children}</StoreContextDispatch.Provider> </StoreContext.Provider> ); }; const useDonationSummaryContext = () => useContext<PropTypes['initialState']>(StoreContext); const useDonationSummaryDispatch = () => useContext(StoreContextDispatch); export {DonationSummaryProvider, useDonationSummaryContext, useDonationSummaryDispatch};