import { useContext } from 'react';
import {
TranslatableContext,
TranslatableContextValue,
} from './TranslatableContext';
/**
* Gives access to the current TranslatableContext.
*
* @example
* }
* locales={['en', 'fr']}
* >
*
*
*
* const MyLanguageSelector = () => {
* const {
* locales,
* selectedLocale,
* selectLocale,
* } = useTranslatableContext();
*
* return (
*
* );
* }
*/
export const useTranslatableContext = (): TranslatableContextValue => {
const context = useContext(TranslatableContext);
if (!context) {
throw new Error(
'useTranslatableContext must be used inside a TranslatableContextProvider'
);
}
return context;
};