context.tsx 680 B

1234567891011121314151617181920212223
  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. export type GoalConfigContextValue = {
  6. items: GoalConfigItem[];
  7. loading: boolean;
  8. saving: boolean;
  9. setSaving: Dispatch<SetStateAction<boolean>>;
  10. fetchList: () => void;
  11. };
  12. export const GoalConfigContext = createContext<GoalConfigContextValue|null>(null);
  13. export function useGoalConfigContext(): GoalConfigContextValue {
  14. const ctx = useContext(GoalConfigContext);
  15. if (!ctx) {
  16. throw new Error('useGoalConfigContext must be used within GoalConfigProvider');
  17. }
  18. return ctx;
  19. }