19 lines
490 B
TypeScript
19 lines
490 B
TypeScript
|
|
import { createContext, useContext, type Dispatch } from "react";
|
||
|
|
import type { SoundPayload, SoundState } from "../types/types";
|
||
|
|
|
||
|
|
type SoundContextType = {
|
||
|
|
state: SoundState;
|
||
|
|
dispatch: Dispatch<SoundPayload>;
|
||
|
|
};
|
||
|
|
|
||
|
|
export const SoundContext = createContext<SoundContextType | undefined>(
|
||
|
|
undefined
|
||
|
|
);
|
||
|
|
|
||
|
|
export const useSoundContext = () => {
|
||
|
|
const ctx = useContext(SoundContext);
|
||
|
|
if (!ctx)
|
||
|
|
throw new Error("useSoundContext must be used within <SoundContext>");
|
||
|
|
return ctx;
|
||
|
|
};
|