@@ -2,7 +2,7 @@ import classNames from 'classnames';
2
2
import Link from 'next/link' ;
3
3
import { useRouter } from 'next/router' ;
4
4
import { useTranslation } from 'next-i18next' ;
5
- import { useCallback , useEffect , useState } from 'react' ;
5
+ import { useEffect , useState } from 'react' ;
6
6
import { AiOutlineAppstore , AiOutlineSetting } from 'react-icons/ai' ;
7
7
8
8
import { TagModal } from '@/components/dialog/TagModal' ;
@@ -27,25 +27,19 @@ export default function TagList() {
27
27
const { tid = '' , sort_by = 'featured' } = router . query ;
28
28
const [ tags , setTags ] = useState < Tag [ ] > ( [ ] ) ;
29
29
30
- const initTags = useCallback ( async ( ) => {
31
- const res = await getTags ( ) ;
32
- if ( res . success ) {
33
- res . data . unshift ( defaultTag ) ;
34
- // 判断当前语言是否为英文,如果是英文则显示英文名称
35
- res . data . forEach ( ( item ) => {
36
- if ( i18n . language == 'en' && item . name_en !== null ) {
37
- item . name = item . name_en ;
38
- }
39
- } ) ;
40
- setTags ( res . data ) ;
41
- }
42
- } , [ ] ) ;
43
-
44
30
useEffect ( ( ) => {
31
+ const initTags = async ( ) => {
32
+ const res = await getTags ( ) ;
33
+ if ( res . success ) {
34
+ res . data . unshift ( defaultTag ) ;
35
+ setTags ( res . data ) ;
36
+ }
37
+ } ;
38
+
45
39
if ( ! isMobile ( ) ) {
46
40
initTags ( ) ;
47
41
}
48
- } , [ i18n . language ] ) ;
42
+ } , [ ] ) ; // 确保 useEffect 只在组件挂载时执行
49
43
50
44
const iconClassName = ( iconName : string ) => `iconfont icon-${ iconName } mr-1` ;
51
45
@@ -80,7 +74,13 @@ export default function TagList() {
80
74
>
81
75
< div className = { tagClassName ( item . tid ) } >
82
76
< div className = { iconClassName ( item . icon_name ) } > </ div >
83
- < div className = 'truncate text-ellipsis' > { item . name } </ div >
77
+ < div className = 'truncate text-ellipsis' >
78
+ { i18n . language == 'zh'
79
+ ? item . name
80
+ : item . name_en
81
+ ? item . name_en
82
+ : item . name }
83
+ </ div >
84
84
</ div >
85
85
</ Link >
86
86
) ) }
0 commit comments