feat(i18n): add i18n types, config, provider, context, and custom hook
This commit is contained in:
9
src/hooks/useLanguage.ts
Normal file
9
src/hooks/useLanguage.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import {
|
||||
LangaugeContext,
|
||||
type LangaugeContextModel,
|
||||
} from '@/contexts/LangaugeContext';
|
||||
import { useContext } from 'react';
|
||||
|
||||
export const useLangauge = (): LangaugeContextModel => {
|
||||
return useContext(LangaugeContext);
|
||||
};
|
||||
17
src/hooks/useLocalStorage.ts
Normal file
17
src/hooks/useLocalStorage.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
export const useLocalStorage = <T extends string>(
|
||||
key: string,
|
||||
defaultValue: T,
|
||||
): [T, (value: T) => void] => {
|
||||
const localValueOrDefault: T = (localStorage.getItem(key) ??
|
||||
defaultValue) as T;
|
||||
|
||||
const [localValue, setLocalValue] = useState<T>(localValueOrDefault);
|
||||
|
||||
useEffect(() => {
|
||||
localStorage.setItem(key, localValue);
|
||||
}, [localValue, key]);
|
||||
|
||||
return [localValue, setLocalValue];
|
||||
};
|
||||
Reference in New Issue
Block a user