context.tsx 767 B

12345678910111213141516171819202122232425
  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. type AlertConfigContextValue = {
  6. items: AlertConfigItem[];
  7. setItems: Dispatch<SetStateAction<AlertConfigItem[]>>;
  8. widgetToken: string|null;
  9. loading: boolean;
  10. saving: boolean;
  11. setSaving: Dispatch<SetStateAction<boolean>>;
  12. fetchList: () => void;
  13. };
  14. export const AlertConfigContext = createContext<AlertConfigContextValue|null>(null);
  15. export function useAlertConfigContext(): AlertConfigContextValue {
  16. const ctx = useContext(AlertConfigContext);
  17. if (!ctx) {
  18. throw new Error('useAlertConfigContext must be used within AlertConfigProvider');
  19. }
  20. return ctx;
  21. }