Skip to content

Commit

Permalink
fix(react): store selected language locally
Browse files Browse the repository at this point in the history
  • Loading branch information
devshred committed Jun 28, 2024
1 parent baeddb6 commit 8feabe0
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/services/providers/language/LanguageProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { ReactNode, useState } from 'react'
import React, { ReactNode } from 'react'
import { useLocalStorage } from '@uidotdev/usehooks'

import LanguageContext from './LanguageContext'
import en from './data/en.json'
Expand All @@ -16,7 +17,7 @@ export const LanguageProvider: React.FC<LanguageProviderProps> = ({
initialLanguage,
children,
}) => {
const [language, setLanguage] = useState<Language>(initialLanguage)
const [language, setLanguage] = useLocalStorage<Language>('gps-tools_language', initialLanguage)
const toggleLanguage = () => setLanguage((currentState) => (currentState === 'en' ? 'de' : 'en'))

const dictionary: LanguageDictionary = { en, de }
Expand Down

0 comments on commit 8feabe0

Please sign in to comment.