configProvider.tsx 690 B

1234567891011121314151617181920212223242526272829
  1. 'use client';
  2. import { createContext, useContext } from 'react';
  3. import Config from '@/types/config';
  4. const ConfigContext = createContext<Config|null>(null);
  5. // Context Provider
  6. export function ConfigProvider({ children, initialConfig }: {
  7. children: React.ReactNode,
  8. initialConfig: Config|null
  9. }) {
  10. return (
  11. <ConfigContext.Provider value={initialConfig}>
  12. {children}
  13. </ConfigContext.Provider>
  14. );
  15. }
  16. // Context 사용을 위한 커스텀 훅
  17. export function useConfigContext(): Config {
  18. const context = useContext(ConfigContext);
  19. if (context === null) {
  20. throw new Error('useConfigContext는 ConfigProvider 내부에서만 사용 가능합니다.');
  21. }
  22. return context;
  23. }