| 1234567891011121314151617181920212223242526272829 |
- 'use client';
- import { createContext, useContext } from 'react';
- import Config from '@/types/config';
- const ConfigContext = createContext<Config|null>(null);
- // Context Provider
- export function ConfigProvider({ children, initialConfig }: {
- children: React.ReactNode,
- initialConfig: Config|null
- }) {
- return (
- <ConfigContext.Provider value={initialConfig}>
- {children}
- </ConfigContext.Provider>
- );
- }
- // Context 사용을 위한 커스텀 훅
- export function useConfigContext(): Config {
- const context = useContext(ConfigContext);
- if (context === null) {
- throw new Error('useConfigContext는 ConfigProvider 내부에서만 사용 가능합니다.');
- }
- return context;
- }
|