Skip to content

Commit d19bff4

Browse files
refactor: Update LanguageProvider props typing
1 parent e59466b commit d19bff4

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/components/Language/context.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@ const LanguageContext = createContext<LanguageContextType | undefined>(
1717
undefined
1818
)
1919

20-
export const LanguageProvider = ({ children }: { children: ReactNode }) => {
20+
interface LanguageProviderProps {
21+
children: ReactNode
22+
}
23+
24+
export const LanguageProvider = ({ children }: LanguageProviderProps) => {
2125
// Get the language from localStorage or default to 'python'
22-
const initialLanguage =
26+
const initialLanguage: Language =
2327
(localStorage.getItem('selectedLanguage') as Language) || 'python'
2428

2529
const [selectedLanguage, setSelectedLanguage] =
@@ -38,10 +42,12 @@ export const LanguageProvider = ({ children }: { children: ReactNode }) => {
3842
)
3943
}
4044

41-
export const useLanguage = () => {
45+
export function useLanguage() {
4246
const context = useContext(LanguageContext)
43-
if (!context) {
47+
48+
if (context === undefined) {
4449
throw new Error('useLanguage must be used within a LanguageProvider')
4550
}
46-
return context
51+
52+
return context as LanguageContextType
4753
}

0 commit comments

Comments
 (0)