2023-03-09 00:47:11 +03:00
|
|
|
import React, { useContext } from "react";
|
2023-02-16 18:09:56 +03:00
|
|
|
import { ReactNode } from "react";
|
|
|
|
import { AudioConfigState, useAudioConfig } from "../001_globalHooks/001_useAudioConfig";
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
children: ReactNode;
|
|
|
|
};
|
|
|
|
|
|
|
|
type AppRootValue = {
|
|
|
|
audioContextState: AudioConfigState
|
2023-02-22 01:35:26 +03:00
|
|
|
|
2023-02-16 18:09:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const AppRootContext = React.createContext<AppRootValue | null>(null);
|
|
|
|
export const useAppRoot = (): AppRootValue => {
|
|
|
|
const state = useContext(AppRootContext);
|
|
|
|
if (!state) {
|
|
|
|
throw new Error("useAppState must be used within AppStateProvider");
|
|
|
|
}
|
|
|
|
return state;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const AppRootProvider = ({ children }: Props) => {
|
|
|
|
const audioContextState = useAudioConfig()
|
|
|
|
const providerValue: AppRootValue = {
|
2023-02-22 01:35:26 +03:00
|
|
|
audioContextState,
|
2023-02-16 18:09:56 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
return <AppRootContext.Provider value={providerValue}>{children}</AppRootContext.Provider>;
|
|
|
|
};
|