PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.17.0
GiveWP – Donation Plugin and Fundraising Platform v4.17.0
4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 All 256 releases
give / src / DonationForms / resources / app / store / index.tsx

index.tsx in GiveWP – Donation Plugin and Fundraising Platform 4.17.0, at src/DonationForms/resources/app/store/index.tsx

38 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import {createContext, ReactNode, useContext, useReducer} from 'react';
2 import type {Gateway} from '@givewp/forms/types';
3 import reducer from '@givewp/forms/app/store/reducer';
4 import {ObjectSchema} from 'joi';
5
6 const StoreContext = createContext(null);
7 StoreContext.displayName = 'DonationFormState';
8
9 const StoreContextDispatch = createContext(null);
10 StoreContextDispatch.displayName = 'DonationFormStateDispatch';
11
12 type PropTypes = {
13 initialState: {
14 gateways: Gateway[];
15 defaultValues: object;
16 validationSchema: ObjectSchema;
17 };
18 children: ReactNode;
19 };
20
21 /**
22 * @since 3.0.0
23 */
24 const DonationFormStateProvider = ({initialState, children}: PropTypes) => {
25 const [state, dispatch] = useReducer(reducer, initialState);
26
27 return (
28 <StoreContext.Provider value={state}>
29 <StoreContextDispatch.Provider value={dispatch}>{children}</StoreContextDispatch.Provider>
30 </StoreContext.Provider>
31 );
32 };
33
34 const useDonationFormState = () => useContext<PropTypes['initialState']>(StoreContext);
35 const useDonationFormStateDispatch = () => useContext(StoreContextDispatch);
36
37 export {DonationFormStateProvider, useDonationFormState, useDonationFormStateDispatch};
38