context.tsx 698 B

123456789101112131415161718192021222324252627282930313233
  1. 'use client';
  2. import { createContext, useContext } from 'react';
  3. type StudioContextValue = {
  4. channelID: number|null;
  5. memberID: number;
  6. };
  7. const StudioContext = createContext<StudioContextValue|null>(null);
  8. export function useStudioContext(): StudioContextValue {
  9. const ctx = useContext(StudioContext);
  10. if (!ctx) {
  11. throw new Error('useStudioContext must be used within StudioProvider');
  12. }
  13. return ctx;
  14. }
  15. type Props = {
  16. channelID: number|null;
  17. memberID: number;
  18. children: React.ReactNode;
  19. };
  20. export function StudioProvider({ channelID, memberID, children }: Props) {
  21. return (
  22. <StudioContext.Provider value={{ channelID, memberID }}>
  23. {children}
  24. </StudioContext.Provider>
  25. );
  26. }