context.tsx 680 B

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