context.tsx 728 B

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