@@ -40,11 +40,9 @@ export function useTranslation(ns, props = {}) {
40
40
41
41
// binding t function to namespace (acts also as rerender trigger)
42
42
function getT ( ) {
43
- return {
44
- t : i18n . getFixedT ( null , i18nOptions . nsMode === 'fallback' ? namespaces : namespaces [ 0 ] ) ,
45
- } ;
43
+ return i18n . getFixedT ( null , i18nOptions . nsMode === 'fallback' ? namespaces : namespaces [ 0 ] ) ;
46
44
}
47
- const [ t , setT ] = useState ( getT ( ) ) ; // seems we can't have functions as value -> wrap it in obj
45
+ const [ t , setT ] = useState ( getT ) ;
48
46
49
47
const isMounted = useRef ( true ) ;
50
48
useEffect ( ( ) => {
@@ -55,12 +53,12 @@ export function useTranslation(ns, props = {}) {
55
53
// in side effect and do not call resetT if unmounted
56
54
if ( ! ready && ! useSuspense ) {
57
55
loadNamespaces ( i18n , namespaces , ( ) => {
58
- if ( isMounted . current ) setT ( getT ( ) ) ;
56
+ if ( isMounted . current ) setT ( getT ) ;
59
57
} ) ;
60
58
}
61
59
62
60
function boundReset ( ) {
63
- if ( isMounted . current ) setT ( getT ( ) ) ;
61
+ if ( isMounted . current ) setT ( getT ) ;
64
62
}
65
63
66
64
// bind events to trigger change, like languageChanged
@@ -81,13 +79,13 @@ export function useTranslation(ns, props = {}) {
81
79
const isInitial = useRef ( true ) ;
82
80
useEffect ( ( ) => {
83
81
if ( isMounted . current && ! isInitial . current ) {
84
- setT ( getT ( ) ) ;
82
+ setT ( getT ) ;
85
83
}
86
84
isInitial . current = false ;
87
85
} , [ i18n ] ) ; // re-run when i18n instance was replaced
88
86
89
- const ret = [ t . t , i18n , ready ] ;
90
- ret . t = t . t ;
87
+ const ret = [ t , i18n , ready ] ;
88
+ ret . t = t ;
91
89
ret . i18n = i18n ;
92
90
ret . ready = ready ;
93
91
0 commit comments