context.tsx 718 B

123456789101112131415161718192021222324
  1. 'use client';
  2. import { createContext, useContext } from 'react';
  3. import type { Dispatch, SetStateAction } from 'react';
  4. import type { AlertConfigItem } from '@/types/response/donation/alertConfig';
  5. export type AlertConfigContextValue = {
  6. items: AlertConfigItem[];
  7. widgetToken: string|null;
  8. loading: boolean;
  9. saving: boolean;
  10. setSaving: Dispatch<SetStateAction<boolean>>;
  11. fetchList: () => void;
  12. };
  13. export const AlertConfigContext = createContext<AlertConfigContextValue|null>(null);
  14. export function useAlertConfigContext(): AlertConfigContextValue {
  15. const ctx = useContext(AlertConfigContext);
  16. if (!ctx) {
  17. throw new Error('useAlertConfigContext must be used within AlertConfigProvider');
  18. }
  19. return ctx;
  20. }