This commit is contained in:
张成
2025-11-16 09:53:24 +08:00
parent 6f4900eb0b
commit ad971796ba
8 changed files with 143 additions and 64 deletions

View File

@@ -1,4 +1,4 @@
import React, { useState, useEffect } from "react";
import React, { useState, useEffect, useCallback } from "react";
import { View, Text, Image, ScrollView } from "@tarojs/components";
import Taro, { useDidShow } from "@tarojs/taro";
import "./index.scss";
@@ -79,14 +79,8 @@ const MyselfPage: React.FC = () => {
// set_user_info(useUserInfo()); // 确保从编辑页面返回时刷新数据
});
// 切换标签页时重新加载球局数据
useEffect(() => {
if (!loading) {
load_game_data();
}
}, [active_tab]);
// 分类球局数据
const classifyGameRecords = (
// 分类球局数据(使用 useCallback 包装,避免每次渲染都创建新函数)
const classifyGameRecords = useCallback((
game_records: TennisMatch[]
): { notEndGames: TennisMatch[]; finishedGames: TennisMatch[] } => {
const now = new Date().getTime();
@@ -104,9 +98,10 @@ const MyselfPage: React.FC = () => {
finishedGames: [] as TennisMatch[],
}
);
};
// 加载球局数据
const load_game_data = async () => {
}, []);
// 加载球局数据(使用 useCallback 包装,避免每次渲染都创建新函数)
const load_game_data = useCallback(async () => {
try {
let games_data;
if (active_tab === "hosted") {
@@ -127,7 +122,14 @@ const MyselfPage: React.FC = () => {
} catch (error) {
console.error("加载球局数据失败:", error);
}
};
}, [active_tab, user_info, classifyGameRecords]);
// 切换标签页时重新加载球局数据
useEffect(() => {
if (!loading) {
load_game_data();
}
}, [loading, load_game_data]);
// 处理关注/取消关注
const handle_follow = async () => {