1
1
import { Select } from 'antd'
2
- import { useContext , useEffect , useState } from 'react'
2
+ import { useContext } from 'react'
3
3
import { useDispatch } from 'react-redux'
4
4
import LanguageContext from '../../contexts/LanguageContext'
5
5
import { emitRootKeyChanged } from '../../redux/actions/GlobalActions'
6
6
import {
7
- getCurrentLanguageOption ,
8
7
languagesOptions ,
9
8
setCurrentLanguageOption ,
10
9
} from '../../utils/Language'
@@ -14,33 +13,25 @@ interface LanguageSelectorProps {
14
13
}
15
14
16
15
const LanguageSelector : React . FC < LanguageSelectorProps > = ( { forceReload } ) => {
17
- const [ currentLanguage , setCurrentLanguage ] = useState (
18
- getCurrentLanguageOption ( ) . value
19
- )
20
-
21
- const { setCurrentLanguageOptionContext } = useContext ( LanguageContext )
16
+ const { currentLanguage, setCurrentLanguageOptionContext } =
17
+ useContext ( LanguageContext )
22
18
23
19
const dispatch = useDispatch ( )
24
20
25
21
const handleChange = ( value : string ) => {
26
22
const langOption = setCurrentLanguageOption ( value )
27
23
setCurrentLanguageOptionContext ( langOption )
28
- setCurrentLanguage ( value )
29
24
dispatch ( emitRootKeyChanged ( ) )
30
25
if ( forceReload ) {
31
26
window . location . reload ( )
32
27
}
33
28
}
34
29
35
- useEffect ( ( ) => {
36
- setCurrentLanguage ( getCurrentLanguageOption ( ) . value )
37
- } , [ ] )
38
-
39
30
return (
40
31
< Select
41
32
style = { { width : 150 } }
42
33
options = { languagesOptions }
43
- value = { currentLanguage }
34
+ value = { currentLanguage . value }
44
35
onChange = { handleChange }
45
36
/>
46
37
)
0 commit comments